android - ListView with multiple kinds of layouts -
my situation following. have 2 layouts
first:
<relativelayout ... > <textview id="@+id/textview1" .../> <textview id="@+id/textview2" .../> <imageview .../> </relativelayout>
second:
<relativelayout ... > <textview id="@+id/textview3" .../> <textview id="@+id/textview4" .../> <imageview .../> </relativelayout>
now i'm gonna make listview these 2 layouts. arrayadapter ready. need create new instance of adapter , i'm stuck here. cause constructor is:
public arrayadapter (context context, int resource, int textviewresourceid, list<t> objects) context current context. resource resource id layout file containing layout use when instantiating views. textviewresourceid id of textview within layout resource populated objects objects represent in listview.
problem & question:
don't know how deal second , third parameters. seems each of 2 parameters has multiple choices. how can initiate adapter?
please make own adapter, maybe extends baseadapter , implement getview() method, change layout depending on each item want. check piece of code, may helps:
public class myadapter extends baseadapter{ private arraylist<string> data; private layoutinflater inflater; public myadapter(arraylist<string> data){ this.data = data; //this data outside } @override public int getcount() { // todo auto-generated method stub return data.size(); } @override public object getitem(int position) { // todo auto-generated method stub return data.get(position); } @override public long getitemid(int arg0) { // todo auto-generated method stub return 0; } @override public view getview(int position, view convertview, viewgroup arg2) { view view = convertview; if(view == null){ if(condition layout 1){ // inflate layout 1 view here // import data data.get(position) view here }else if(condition layout 2){ // inflate layout 2 view here // import data data.get(position) view here } } return view; } }
Comments
Post a Comment