android - 如何从 Listview 中获取列表项的数量?

标签 android listview

我正在使用下面的代码遍历我的列表,如果列表项可见,它工作正常。

如果 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/

相关文章:

android - 如何在QT上将SQLite导出到apk?

android - 显示操作栏菜单按钮

android - 通知适配器后,notifyDataSetChanged() 不会更新 ListView

Android如何在Android中实现这个listview?

c# - Foreach ListView 中的子项

android - 从我的网站在 Android 应用程序中安装更新

Android - 多线程导致应用程序崩溃

android - 无法在 android studio 3.6 中进行 git pull

c# - ListView:从 ListViewItem 获取实际的项目对象

listview - Xamarin.Forms ListView 禁用 UWP 上的选择