Skip to content Skip to sidebar Skip to footer

Android: Custom Adapter For Handling More Than One Araystringlists

I have a Row layout, with two textViews, lets say textViewX and textViewY. I know how to populate one textView with one arrayList using the Adapter. How do I make a custom Adapte

Solution 1:

Use a Model Class

classModel
{
String value1;
String value2
publicvoidsetValue1(String value1)
{
this.value1=value1;
}
publicvoidsetValue2(String value2)
{
this.value2=value2;
}
publicStringgetValue1()
{
returnthis.value1;
}
publicStringgetValue2()
{
returnthis.value2;
}
}

Now in Activity

 ArrayList<Model> aa = new ArrayList<Model>();

Now populate the list say using for loop. Below is just an example. Just make sure you populate the list.

for(int i=0;i<10;i++)
 {
 Model model = new Model();
 model.setValue1("value1");
 model.setValue2("value2");
 aa.add(model);
 } 

Pass list aa to CustomAdapter and use it there

In getView

 Model mo = (Model) aa.get(position);
 tv1.setText(mo.getValue1());
 tv2.setText(mo.getValue2());

Post a Comment for "Android: Custom Adapter For Handling More Than One Araystringlists"