I have an alertDialog with a ListView in it. By default it is showing all the items it can fit on dialog screen, but I would like to limit this to i.e. 3 items at a time. How can I achieve this? This is an excerpt of my code, not relevant parts are omitted
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
if ((event.getKeyCode() == KeyEvent.KEYCODE_ENTER) || (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER)){
if (event.getAction() == KeyEvent.ACTION_UP){
ArrayList<HashMap<String, String>> names = new ArrayList<HashMap<String, String>>(totalItems);
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
View rowList = getLayoutInflater().inflate(R.layout.activity_list, null);
ListView listView = rowList.findViewById(R.id.listView);
String[] from = new String[] { "title", "description" };
int[] to = new int[] { android.R.id.text1, android.R.id.text2 };
int nativeLayout = R.layout.list_item;
SimpleAdapter simpleAdapter = new SimpleAdapter(this, names, nativeLayout , from, to);
listView.setAdapter(simpleAdapter);
simpleAdapter.notifyDataSetChanged();
alertDialog.setView(rowList);
listDialog = alertDialog.show();
this is the listview layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorMenuBackground">
<ListView
android:id="@+id/listView"
android:listSelector="@color/colorMenuBackgroundSelected"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</ListView>
</RelativeLayout>