0

我想从数据库中调用数据并将其设置在列表适配器上。然后希望选择一个特定的项目并显示其相应的信息。到目前为止,我可以调用数据并设置列表适配器。现在如何从列表中选择特定项目。

我尝试将数据从评论转换为字符串,但这不起作用。

 List<Comment> values = datasource.getAllComments();

Array Adapter<Comment> adapter = new ArrayAdapter<Comment>(this,
        android.R.layout.simple_list_item_1, values);
    setListAdapter(adapter);
4

1 回答 1

0

在 ListView 的 OnClickListener 上做这样的事情

LV.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long id) {
            myDialog = new Dialog(Dealer_data.this);
            myDialog.setContentView(R.layout.detail_dealer);
            myDialog.getWindow().setLayout(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
            myDialog.setTitle("Dealer Details");
            myDialog.setCancelable(true);

            TextView t1;
            t1 = (TextView) myDialog.findViewById(R.id.textView1);
            int a=1;
            int add_pos= position+a;
            //Toast.makeText(getApplicationContext(), "Position after add= "+add_pos, Toast.LENGTH_LONG).show();

            deal_id=""+add_pos;
            pos = new ArrayList<String>();
            Cursor col =dbCarHelper.getdealer(deal_id);
            for (col.moveToFirst(); !col.isAfterLast(); col.moveToNext()) {
                // The Cursor is now set to the right position
                pos.add(col.getString(0));
                pos.add(col.getString(1));
                pos.add(col.getString(2));
                pos.add(col.getString(3));
                pos.add(col.getString(4));
                pos.add(col.getString(5));
                pos.add(col.getString(6));
                pos.add(col.getString(7));
                pos.add(col.getString(8));
                pos.add(col.getString(9));
            //  pos.add(col.getString(10));
            }

            full_detail = "Car Make : " + pos.get(0) + "\nState : " + pos.get(1)
                    + " \nCity : " + pos.get(2) + "\nCompany Name : " + pos.get(3)
                    + "\nCompany Address : " + pos.get(4) + "\nPhone : " + pos.get(5)
                    + "\nMobile : " + pos.get(6) + "\nFax : " + pos.get(7)
                    + "\nEmail : " + pos.get(8) + "\nWebsite : " + pos.get(9);
            t1.setText(full_detail);
            myDialog.show();

        }
    });
于 2013-10-19T11:28:14.310 回答