Reusing Layout Xml And The Code Behind

I am trying to turn a couple buttons into a reusable component in android. I have successfully gotten the xml / ui portion working, but i can't figure out how to make code behind it reusable between activities, short of recoding it everywhere.

I've already reviewed this post several times: android layout tricks 3 - part 1 but it seems to be missing a few files, and i do not have enough experience to rebuild them.

A dumbed down version of my main layout:


And then of my "component":


If you have any additional critiques on my xml.

View Full Post With 2 Replies

Related Forum Messages:

Please Follow Index to Quick Jump to the Message.

Reusing Code - Multiple External Namespaces

What's the proper way to share code and layouts between android projects?  (I work with eclipse)

Explanation and my problem:

I'm working in multiple projects that share the same base (an activity-less android project). This project have some graphical classes with its layouts in xml and require both to work properly. Normally i copy this code and change the r. Id definitions on the project to match the current 'sub-project' but, obviously, this is not the proper way of reusing code.

Now i have two eclipse projects, one of them has the 'base' code and the other is the current application. I defined a dependency but it seems that i can refer to the classes from java, but i can't in this other project's layouts. I tried declaring its namespace in xml files, but it doesn't work.

I can't believe the way is copy+paste and search+replace.

Posted On: Jun 14 2009 . View Related Posts . . View 2 Replies .

How To Reuse Layout.xml

In my activity, i have the following in my layout.xml file. Can you please tell me how can i make it 'resuable'?  For example, i what to create a library so that i can insert a component and it creates 4 buttons for me using linear layout? How can i combine all that into a 'view' or a widget?

Posted On: Feb 18 2009 . View Related Posts . . View 2 Replies .

Create Table Layout Without Using Droid Xml

How to create table layout with out using the android xml.

Posted On: Feb 3 2009 . View Related Posts . . View 3 Replies .

Use An Intent Go To A Layout In My Main Xml File

Anyone know how to use an intent to display the view of one of my child layouts in my parent xml layout? I am using viewflipper and want a button to be clicked to display a specific view in my xml file:

Ie, something like this code.

Posted On: Nov 22 at 0:33 . View Related Posts . . View 1 Replies .

Insert More Stuff In An Xml Loaded Layout

I'm using setcontentview(r. Layout. Somelayout); to load an xml to my activity.
On this layout, there is a framelayout, i want to insert more objects in it dynamically, as an example, more button objects.

I haven't found some getcurrentview() method yet. So, how can i get the current layout from the activity?

Posted On: Apr 27 at 19:59 . View Related Posts . . View 1 Replies .

How To Reference Native Drawable In Layout Xml

How to reference native android drawable in the layout xml ?

Posted On: Jun 11 2009 . View Related Posts . . View 2 Replies .

Draw A Rectangle On Screen Using Layout.xml File

I am trying to draw a rectangle using layout.xml file without java code. So this is what i tried code.

Can you please tell me how can i do it?

Posted On: Apr 26 2009 . View Related Posts . . View 2 Replies .

Set Scrolllayout Dynamically Not In Xml Layout File?

I have android code the display a list of users information , and sometime it needs to have a scroll bar to display all users ?And sometimes not. How can i set scrolllayout dynamically not in xml layout file ?

Posted On: Nov 17 at 19:42 . View Related Posts . . View 3 Replies .

Layout - Inflate An Xml Into The Class Which Extending View

I create a subclass of view as an inner class in my activity. I just want to inflate an xml into the class which extending view.

Can anyone provide some code/syntax of both class and xml?


Xml is


Posted On: Oct 5 at 5:20 . View Related Posts . . View 3 Replies .

Modify .xml Layout File In Order To Make Elements Inside Linearview Same Size

I would like to create a dialog to display a video title and tags. Below text i would like to add buttons view, edit and delete and make these elements same size. Does anyone know how to modify .xml layout file in order to make elements inside linearview same size?

The current layout file looks like this code.

Posted On: Jul 24 09 at 11:15 . View Related Posts . . View 2 Replies .

Particular Collection Of Code Along With Some Xml Files

I have a particular collection of code along with some xml files that i need to share with every application i will make.

At the moment i can't because as far as i am aware there is no way to do this. This seems like a massive oversight by the development team.

If the code needs changing, i have to change it in every app that i create - and will create in the future.

Are there any ways to share code in android yet? I am using eclipse for development.

Posted On: Jun 4 at 15:06 . View Related Posts . . View 3 Replies .

Possible To Edit Strings.xml From Inside .java Code?

Is it possible to edit a string in my strings.xml from within my java code? I'd like my app_name to be changed dynamically based off of user input.

Posted On: Oct 5 2009 . View Related Posts . . View 2 Replies .

Draw Borders For Textview Created Using Code Not By Xml In Droid

I created my textview through code rather than xml. I want to draw a border around the textview. How can we do this using code rather than xml? I also wanted when i try to settext for the textview which is of some 2 lines then textview is moving downward?

Posted On: Oct 13 at 10:10 . View Related Posts . . View 1 Replies .

Samsung Galaxy S - Reusing Launcherpro

I used lp for a while then cleared it as default and then gave tw another go. Now i wanna try lp again but i don't know how to set it as my default home screen again? I can't find it in my app draw? How do i start it again?

Posted On: 09-09-2010, 12:24 AM . View Related Posts . . View 7 Replies .

Reusing A Thread - Get Some Remote Data From Server

I am trying to get my head around threads, and after attempting many times to get my head around it, i am stuck on this point.

I want to get some remote data from a server. I create a thread to handle this operation. I understand this. But if i want to get some more remote data, i end up creating a new thread. This seems a bit daft, as shouldnt i be able to re-use the existing thread.

After trying to understand how i could do this, i think the answer lies in sending messages to the thread? But i am totally baffled by this.

Here is a example of where i need to get lots of remote data based on a variable within a for statement:


As you can see in the example, i need to call the remote server lots of times, but instead of creating a new thread each time, shouldnt i be able to reuse one thread that i can create earlier?

Posted On: Oct 10 at 10:40 . View Related Posts . . View 1 Replies .

Reusing Tts-object On Multiple - Different Activitys In App

I'm program an android-app for blind people. So i'm using tts on every activity in my app.

I don't want to initialize tts on every activity again because it takes time and resources, so i'm creating a tts-object in my application class and use it on the activitys. It works fine.

But documentation says you have to something like this:


But i can't do this because i don't want to shutdown my shared object (each time a activity is destroyed) but if my programm get's distroyed it i should shutdown it.

So: where to call . Shutdown() ? Or does anybody know a better way to ensure that tts is loading quickly?

Posted On: Nov 7 at 13:20 . View Related Posts . . View 1 Replies .

Php Xml Response Aftersax Parsing - Xml Or Text Declaration Not At Start Of Entity

I need to parse this php xml response in android:


Posted On: Feb 24 at 15:30 . View Related Posts . . View 1 Replies .

Layout Designing Tools

Dose any tools existing for our android layout design? I mean just drag the buttons, edittext, layouts. Etc and that tool generate the xml file for our layout. Anybody know about this tool.

Posted On: Sep 16 at 11:35 . View Related Posts . . View 2 Replies .

Imageview Layout - Startactivityforresult

I have a imageview layout where one image need to be displayed on user selection.

If i click on image, it start a new activity for image selection and display that image on the previous activity image layout.

Activity 1:  


Activity 2:


Posted On: Feb 26 2009 . View Related Posts . . View 2 Replies .

Add & Delete View From Layout

How can i add & delete view from a layout?

Posted On: Sep 27 at 16:00 . View Related Posts . . View 2 Replies .

Not Able To Table Layout Rowspan / Fix It

I want to build the following layout but it is not working.code.

Posted On: Feb 3 at 5:55 . View Related Posts . . View 2 Replies .

Place Textview On Right And Left Of Layout

I want to place a textview on the right of a layout and on the left of a layout, but they keep stacking ontop of each other code.

Posted On: Aug 27 at 4:44 . View Related Posts . . View 2 Replies .

Inflator To Generate New View From Layout

In my custom adapter, that implements the baseadapter and its getview, i use the inflator to generate a new view from a layout. Is there any way to avoid repetitive inflation step? Specially when the convert view (an argument to the getview) is always null, which mean it cant be reused and the view needs to be re-inflated. I was looking for something like a copy or clone but fund none.

Posted On: Dec 7 2009 . View Related Posts . . View 4 Replies .

Copy Android.r.layout To My Project

I'm trying to copy android. R. Layout to my project to ensure consistency.

How do you do this?

I looked in eclipse's package explorer and under
Android 1. 5>android. Jar>android>r. Class>r>layout and find r$layout. Class.

Do i copy the code out of there into my own class? From my very limited knowledge of java, the following code doesn't make much sense:


Inner classes:


Posted On: Apr 1 at 20:32 . View Related Posts . . View 2 Replies .

Layout - Making Three Tables With One Column

I need to represent the following diagram: each x will be an image button. I was thinking of making three tables with one column each and have each cell height be half the height of the table. The problem is that the table needs to be able to stretch or shrink because i am worried about getting everything on the screen and the tables are the only part that can change size and have the entire thing still look ok. The problem i am having is that the rows are only as big as the image buttons. While all the image buttons are the same size, the left and right table in particular, need to have some padding around the image buttons to make it alright. I would add margins to the buttons but that defeats the reshaping problem i am having. I think.

Posted On: Nov 5 at 18:32 . View Related Posts . . View 3 Replies .

Possible To Layout Children That Flows In Different Directions

I want to lay two textview to the left, and one button to the right inside a linear layout, is this possible?
The following is my code where i had to hardcode the leftmargin of the button, this is inflexible. Is it possible to layout children that flows in different directions? Code.

Posted On: Jul 8 09 at 23:49 . View Related Posts . . View 3 Replies .

Can Make Own Appwidgets List Layout

I am trying to create a home application that contains appwidgets. Can i make a own appwidgets list layout that includes appwidgethostview without appwidget_pick intent?I mean i wanna make a visual appwidget list. Actualy i made it, but i couldn't start appwidget some like music widget. I think it does not contain a intent. How can i get the appwidgets intent ?

Posted On: Oct 6 2009 . View Related Posts . . View 2 Replies .

What's Best Way To Wait For View To Layout

I'm currently playing with this android stuff, doing some image manipulation using image view and matrices for a simple comic book viewer i'm writing. I want to be able to scale the image that i send to the image view to fit the size of the view as it is presented on the screen but when i call imageview. Getheight() it returns 0.

I know i have to wait for it to be laid out before i can get what this value should be but i don't know what the correct way to go about this is. I tried a basic loop that checked the height returned and kept checking until it returned something that wasn't 0 but this simply gave an infinite series of 0's returned.

What's the best way of doing this?

Posted On: Jun 17 2009 . View Related Posts . . View 2 Replies .

Add View To Layout By Z Index

I have a project that needs to change the displayed content dynamically i know i can remove then add a new view to my layout.code.

And then dynamically change the view of layer a.

At the layout is built, it works perfect. But when i programatically remove the view and add a new view. The new view covers the layer b.

I found there is no z index attribute for me to set in the viewgroup.could anyone tell me how to achieve this request ? I'm currently using the absolutelayout.

Posted On: Nov 22 . View Related Posts . . View 2 Replies .