这是一道关于Android编程的题。我需要限制 ListView
中可见行的最大数量。
在 onCreate
方法中,我有我的 ListView
的下一个代码:
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayListOfElements));
在 onPostExecute
方法中我有下一个适配器:
ArrayAdapter<String> adapter = (ArrayAdapter<String>) arrayListOfElements.getAdapter();
adapter.notifyDataSetChanged();
所以我需要为我的适配器设置最大行数,我不关心 ListView
是否可滚动。有什么想法吗?
最佳答案
在您的基本适配器中执行此操作(mList 是您要在 ListView 中显示的项目列表):
public int getCount() {
if (mList != null) {
return Math.min(mList.size(), YOU_MAX_VALUE);
} else {
return 0;
}
}
关于java - 设置 ListView 的最大行数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36142514/