Android列表查看一行的单个值

时间:2012-06-25 14:15:16

标签: android listview

可以获得单行的值。 在partycular中,我不会在我的mt list行中使用适配器获取id的值。

每行都有值id和标签

非常多,对不起我的英语

ListView list;
            list = (ListView) findViewById(R.id.listView1);
            mSchedule = new SimpleAdapter(getApplicationContext(), result ,R.layout.row_meteo,
                    new String[]{"id", "label"}, new int[] {R.id.textView1,R.id.textView2});
            list.setAdapter(mSchedule);

            list.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {
                    String idPlace = mSchedule.getItem(position).toString();

                    Toast.makeText(getApplicationContext()," Cliccato sul luogo :"+idPlace,Toast.LENGTH_LONG).show();


                }
        }

2 个答案:

答案 0 :(得分:1)

 public void onItemClick(AdapterView<?> parent, View view,
                        int position, long id) {


                    TextView tv  = (TextView)view.findViewById(R.id.textView1); //<---------
                    String str = tv.getText();


                }

答案 1 :(得分:0)

替换

String idPlace = mSchedule.getItem(position).toString();

String idPlace =((TextView)view.findViewById(R.id.textView1)).getText().toString();