2

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

4

1 回答 1

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

于 2012-12-13T11:13:57.290 回答