Android 计算 ListView 中列表项的总数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23708271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:22:17 来源:igfitidea点击:
Count Total Number of List Items in a ListView
提问by Sophie
How to count Total Number of List Items in a ListView ?
如何计算 ListView 中列表项的总数?
I am writing a Church Application in which i am populating list using images stored into SD Card, but now i want to count total number of list items.
我正在编写一个教堂应用程序,其中我使用存储在 SD 卡中的图像填充列表,但现在我想计算列表项的总数。
// to upload whole list
for(int position = 0; position < lstView.getAdapter().getCount(); position++)
{
flags.put(position, true);
}
((BaseAdapter) lstView.getAdapter()).notifyDataSetChanged();
}
});
/*** Get Images from SDCard ***/
listSDCardImages = fetchSDCardImages();
// ListView and imageAdapter
lstView = (ListView) findViewById(R.id.listSDCardImages);
lstView.setAdapter(new ListSDCardImagesAdapter(this));
Toast.makeText(getApplicationContext(), "Total number of Items are:" + String.valueOf(position), Toast.LENGTH_LONG).show();
}
Everytime i am getting 0
每次我得到0
回答by EminenT
Total list view count is
列表查看总数为
lstView.getAdapter().getCount() ,
So use
所以用
Toast.makeText(getApplicationContext(), "Total number of Items are:" + lstView.getAdapter().getCount() , Toast.LENGTH_LONG).show();