我有一个这样的 ListView
companyname symbol
samsung sam
onida ond
tata ta
. .
. .
. .
所以我想获取所选项目的索引以及所选项目的字符串(即,sam(或)ond(或)ta)。所以请告诉我如何获取所选项目和字符串的索引还有。
提前致谢
最佳答案
这样使用
listview.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
{
public void onItemSelected(AdapterView parentView, View childView, int position, long id)
{
String text = ((TextView)childView.getText()).toString();
//The above text variable has the text value of selected item
// position will reflect the index of selected item
}
public void onNothingSelected(AdapterView parentView)
{
}
});
关于android - 如何在android中的listview中获取所选项目的索引和字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4554435/