Displaying ArrayList items in ListView contains 2 textviews

后端 未结 3 1193
[愿得一人]
[愿得一人] 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:38

    Its clear from your question that you want to display [a1, a2, b1, b2, c1, c2...] as

    a1a2
    b1b2
    c1c2
    

    so you need to change your code to following:

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        if(myList.size()%2==0)
            return mylist.size()/2;
        else
            return myList.size()/2+1;
    }
    

    and getView method as below:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
    
        View List;
        if(convertView==null)
        {
            List=new View(context);
            LayoutInflater mLayoutinflater=(LayoutInflater)context.getSystemService(context.LAYOUT_INFLATER_SERVICE);
            List=mLayoutinflater.inflate(R.layout.listitem_row, parent, false);
        }
        else
        {
            List=(View)convertView;
    
        }
    
        TextView t1=(TextView)List.findViewById(R.id.txtViewTitle);
        t1.setText((CharSequence) mylist.get(position*2));
    
    
        TextView t2=(TextView)List.findViewById(R.id.txtViewDescription);
        if(position*2

提交回复
热议问题