tags:

views:

36

answers:

1

I have to dynamically add a list of views (the views use RelativeLayout). Can I do this by specifying the view definition in xml and instantiate multiple objects off it? This gives the usual benefits of separating the view part from the code (for e.g., making it easy for the UI guys to alter things) or Is going the ArrayAdapter the suggested/only route?

A: 

are you saying that you want to do this?

View v1 = (View) findViewById(R.id.someView);
View v2 = (View) findViewById(R.id.someView);

If you do this, you will merely have 2 references to the same view; it does not create two separate View objects. However, if you want to make a vertical list of views, look into ListActivity. in this case you will make a layout xml that will be used for every item in the list. you will need to implement a ListAdapter, or use a SimpleArrayAdapter.

does that help?

mtmurdock
Yes, I wanna do something similar but not get references to the same view. Was just curious if there's a way to get instance of 'similar' objects, as I thought it's logical for such a thing to exist. On using ListActivity, the view part (list) I am talking about is just part of an activity i.e., there are other views besides this list that should be shown within the activity.
actually a list activity can look however you want it to. you can lay it out however you want as long as it contains a ListView.
mtmurdock
@mtmurdock: Thanks for the reply, I used inflater for now, ListActivity, ListView seem more elegant.
technically ListActivity and ListView are the same thing, its just a design decision. Remember: if you like an answer, accept it and vote on it.
mtmurdock