Android列表适配器中是否有值成员属性?

时间:2012-12-13 10:38:17

标签: android android-listview adapter

在android中的适配器中是否有可能显示成员和值成员?这意味着listView的value成员将被隐藏

1 个答案:

答案 0 :(得分:0)

您需要做的是构建一个包含对象列表的自定义Adapter

对象

public class MyObject {
    private int id;
    private String name;
}

适配器

public class MyObjectListAdapter extends ArrayAdapter<MyObject> {
    private final Context  context;

    public MyObjectListAdapter(Context context, List<MyObject> objects) {
        super(context, R.layout.listview_myobjects, objects);
        this.context = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View rowView = inflater.inflate(R.layout.listview_myobject_item, parent, false);

        TextView textViewName = (TextView) rowView.findViewById(R.id.textViewObjectName);

        MyObject current = getItem(position);
        textViewName.setText(current.getName());
        return rowView;
    }
}

Lars Vogel详细介绍了ListView,详情请看: http://www.vogella.com/articles/AndroidListView/article.html