安卓列表适配器中是否有值成员属性



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

您需要

做的是构建一个包含对象列表的自定义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;
    }
}

拉尔斯·沃格尔详细介绍了ListView,因此有关更多信息,请查看此处:http://www.vogella.com/articles/AndroidListView/article.html

最新更新