0

ormlite から返された arraylist からリスト ビューを作成したい

これは、ormlite からデータを取得するコードです。

テーブルのすべての列をリストビューに取り込むにはどうすればよいですか

public class dinnerList extends Activity {
ArrayList<CanteenTagEntry> dinnerlist;
ListView lv;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.listview_item_row);

    Context con = getApplicationContext();
    DatabaseHelper dbHelper = new DatabaseHelper(con);
    ICanteenLogRepository canteenrepo = dbHelper.getCanteenLogRepository();
    try {
        dinnerlist = (ArrayList<CanteenTagEntry>) canteenrepo.Retrieve();
        System.out.print(dinnerlist);
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    lv = (ListView) findViewById(R.id.list);
    lv.setAdapter(new CanteenAdapter(this, dinnerlist));

私のアダプタークラスは以下です

public class CanteenAdapter extends BaseAdapter {
    private Context context;
    private List<CanteenTagEntry> lis;

    public CanteenAdapter(Context c, List<CanteenTagEntry> li) {
        // TODO Auto-generated method stub
        context = c;
        lis = li;
    }

    public int getCount() {
        // TODO Auto-generated method stub
        return lis.size();
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (convertView == null) {
            convertView = inflater
                    .inflate(R.layout.listview_item_row, null);
        }

        TextView textview1 = (TextView) convertView
                .findViewById(R.id.Title1);
        TextView textview2 = (TextView) convertView
                .findViewById(R.id.Title2);
        TextView textview3 = (TextView) convertView
                .findViewById(R.id.Title3);
        TextView textview4 = (TextView) convertView
                .findViewById(R.id.Title4);

        return convertView;

    }

}

事前に感謝

4

1 に答える 1

2

これらの値は、アダプタの getView() メソッドで次のようにリストから取得する必要があります

CanteenTagEntry entry = new CanteenTagEntry();
entry = lis.get(position);

このチュートリアルのリストビューのカスタムアダプターを見て、問題を解決してください..

于 2012-08-23T05:07:50.273 に答える