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 が について詳しく説明しています。詳細については、 httpListView : //www.vogella.com/articles/AndroidListView/article.html を参照してください。

于 2012-12-13T11:13:57.290 に答える