You can easily use ListPopupWindow
and any convenient for you adapter
:
// create any adapter with any data, just as for ordinary ListView
SimpleAdapter simpleAdapter= new SimpleAdapter(this, dataSet, android.R.layout.simple_list_item_2,
new String[] {"Name", "Tel. no."},
new int[] {android.R.id.text1, android.R.id.text2});
ListPopupWindow listPopup = new ListPopupWindow(this); // feed context to ListPopupWindow
listPopup.setAdapter(simpleAdapter); // set adapter to created ListPopupMenu
listPopup.setAnchorView(findViewById(id));
// id - any id of any view on the screen. Under this view popup appears. It may be MenuItem as well
listPopup.setWidth(getWidestView(simpleAdapter));
// as popup width equals the anchor width, use getWidestView method for proper list displaying.
// ListPopupWindow.WRAP_CONTENT won't work here
listPopup.show();
getWidestView
snippet you can find here: https://stackoverflow.com/a/13959716/4890659
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…