Displaying ArrayList items in ListView contains 2 textviews

后端 未结 3 1257
[愿得一人]
[愿得一人] 2021-01-26 13:25

I want to display the arrayList items in ListView which is having 2 different textViews. I am using ListViewCustomAdapter and getView(),getItem()... methods are there.

3条回答
  •  耶瑟儿~
    2021-01-26 13:47

    your adapter getview is perfect, but your logic is wrong.. I would prefer making class object with 2 strings, like.

    public class MyClass
    {
      String one;
      String two;
    }
    

    and make your list like

    ArrayList mylist = new ArrayList();
    

    and then setText like you want.

    TextView t1=(TextView)List.findViewById(R.id.txtViewTitle);
    t1.setText(mylist.get(position).one);           //String one= "a1" according to position in mylist
                                                    //it will be = "b1" on next position
                                                  //no need of casting to CharSequence
    
    TextView t2=(TextView)List.findViewById(R.id.txtViewDescription);
    t2.setText(mylist.get(position).two);           //String two= "a2"
    

提交回复
热议问题