显示List的所有产品

时间:2012-06-11 09:34:00

标签: android listview view

我正在尝试在我的数据库列表中显示活动中的所有产品。我使用了NewView和BindView。而不是向我展示所有元素(条形码,格式,标题,价格),我只看到最后的价格。感谢任何解决方案! :)这是代码的一部分:

        Cursor cursor = db.rawQuery("select * from " + PRODUCT_TABLE, null);

        setListAdapter(new CursorAdapter(this, cursor, true) {

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent){

            TextView textView = new TextView(ProdottiSelectionActivity.this);
            textView.setText(cursor.getString(cursor.getColumnIndex("barcode")));
            textView.setText(cursor.getString(cursor.getColumnIndex("format")));
            textView.setText(cursor.getString(cursor.getColumnIndex("title")));
            textView.setText(cursor.getString(cursor.getColumnIndex("price")));
            return textView;
        }

        @Override
        public void bindView (View view, Context context, Cursor cursor){

            TextView textView = (TextView) view;
            textView.setText(cursor.getString(cursor.getColumnIndex("barcode")));
            textView.setText(cursor.getString(cursor.getColumnIndex("format")));
            textView.setText(cursor.getString(cursor.getColumnIndex("title")));
            textView.setText(cursor.getString(cursor.getColumnIndex("price")));

            }
        });

1 个答案:

答案 0 :(得分:1)

使用textView.append()代替setText