This is a question about Android programming. I need to limit the maximum number of visible rows in my ListView.
In onCreate method I have the next code for my ListView:
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, arrayListOfElements));
In onPostExecute method I have the next adapter:
ArrayAdapter<String> adapter = (ArrayAdapter<String>) arrayListOfElements.getAdapter();
adapter.notifyDataSetChanged();
So I need to set a maximum number of rows for my adapter, I don't care if the ListView will be scrollable or not. Any idea?
Do this in your base adapter (mList is your list of items to show in the listview):
public int getCount() {
if (mList != null) {
return Math.min(mList.size(), YOU_MAX_VALUE);
} else {
return 0;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With