如何阅读来自ListView的项目的描述文本?

时间:2015-10-12 05:06:30

标签: android listview textview

我想在Activity中创建一个带有几个项目的ListView(比如Item1 item2 item3 ..),当我点击(比如item1)时,它会进入下一个Activity,给我一个TextView(描述文本)和第2项和第3项的重复次数相同。我怎么能这样做?

3 个答案:

答案 0 :(得分:0)

您可以添加Listview setOnItemClickListener并获取文字说明。

list_view.setOnItemClickListener(new OnItemClickListener() {

   public void onItemClick(AdapterView<?> arg0, View arg1,int arg2,
        long arg3) {
          String description=alist.get(arg2);

        }
    });

答案 1 :(得分:0)

检查此代码

    list_view.setOnItemClickListener(new OnItemClickListener() {

   public void onItemClick(AdapterView<?> arg0, View arg1,int arg2,
        long arg3) {
           TextView text = (TextView) view.findviewbyid(text view reference);
          String description=text .gettext();

        }
    });

答案 2 :(得分:0)

使用

list_view.setOnItemClickListener(new OnItemClickListener()
{
    public void onItemClick(AdapterView<?> adapter, View view,int position, long arg3) 
    {
          String description = datalist.get(position);// datalist is the list of data which is use to create listview
          Intent intent = new Intent(FirstAcitivity.this, Activity2.class);
          intent.putExtra("description", description);// sending value to next activity

    }
});

在您的Activity2中(点击/点击用户移动后的目标活动)

String description = getIntent().getExtras().getString("description");// get description/value from activity which called this (Activity1)