0

我想在列表视图行中使用多个(2)文本视图。我想我必须创建自定义适配器,但是有了这个适配器,我想在单击如下按钮时使用插入多个数据来定位 0:mAdapter.insert(mytext1, mytext2, 0);

但我无法通过示例适配器实现这一点:

public class Durations {
            private String name;
            private String address;

            public Durations(String name, String address) {
                this.name = name;
                this.address = address;
            }
            public void setName(String name) {
                this.name= name;
            }
            public String getName() {
                return name;
            }
            public void setAddress(String address) {
                this.address= address;
            }
            public String getAddress() {
                return address;
            }
        }



      public class CustomAdapter extends ArrayAdapter {
            private final Activity activity;
            private final List list;

            public CustomAdapter(Activity activity, ArrayList<Durations> list) {
                this.activity = activity;
                this.list = list;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View rowView = convertView;
                ViewHolder view;

                if(rowView == null)
                {
                    // Get a new instance of the row layout view
                    LayoutInflater inflater = activity.getLayoutInflater();
                    rowView = inflater.inflate(R.layout.row, null);

                    // Hold the view objects in an object, that way the don't need to be "re-  finded"
                    view = new ViewHolder();
                    view.retaurant_name= (TextView) rowView.findViewById(R.id.text1);
                    view.restaurant_address= (TextView) rowView.findViewById(R.id.text2);

                    rowView.setTag(view);
                } else {
                    view = (ViewHolder) rowView.getTag();
                }


                return rowView;
            }

            protected  class ViewHolder{
                protected TextView retaurant_name;
                protected TextView restaurant_address;
            }



        }
4

1 回答 1

0

您需要为此覆盖 ArrayAdapter 函数。由于您使用的是 ViewHolder,因此它也将重用布局。

getItem(int position)
getItemId(int position)

您也可以轻松找到基于定义自定义适配器的各种教程。

于 2013-04-30T04:26:24.310 回答