我正在使用下面的代码遍历我的列表,如果列表项可见,它工作正常。
如果 List 是可滚动的,则不可见的项目不会使用此代码进行访问。如何遍历所有可见+不可见的列表项。
for(int i=0;i<list.getCount;i++)
{
View v = list.getChildAt(i);
TextView tv= (TextView) v.findViewById(R.id.item);
Log.d("","ListItem :"+tv.getText());
}
最佳答案
下面是如何在 Activity 中获取 ListView 并遍历它。
ListView myList = getListView();
int count = myList.getCount();
for (int i = 0; i < count; i++)
{
ViewGroup row = (ViewGroup) myList.getChildAt(i);
TextView tvTest = (TextView) row.findviewbyid(R.id.tvTestID);
// Get your controls from this ViewGroup and perform your task on them =)
}
希望对你有帮助
关于android - 如何从 Listview 中获取列表项的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4895089/