当我们在android中单击它时,如何在列表项中获取文本?

时间:2012-11-21 08:52:40

标签: android-listview

这是我的代码段:

protected void onListItemClick(ListView l, View v, int position, long id) {
   super.onListItemClick(l, v, position, id);
   Toast.makeText(MainActivity.this, "clicked " + 
     position, Toast.LENGTH_SHORT).show();
}

1 个答案:

答案 0 :(得分:0)

您可以点这个链接:

ArrayList<String> list;
listView.setOnItemClickListener(new OnItemClickListener() 
{

            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                    long arg3) 
{
                ArrayList<String> newList=new ArrayList<String>();
                newList=list.get(position);//Text will be featch according to the position
                String name=newList.get(0).toString(); 
    }
}