android: smoothScrollToPosition() not working correctly

I’m trying to smoothly scroll to last element of a list after adding an element to the arrayadapter associated with the listview. The problem is that it just scrolls to a random position arrayadapter.add(item); //DOES NOT WORK CORRECTLY: listview.smoothScrollToPosition(arrayadapter.getCount()-1); //WORKS JUST FINE: listview.setSelection(arrayadapter.getCount()-1); Answer You probably want to tell the ListView to post the scroll … Read more

Detecting which selected item (in a ListView) spawned the ContextMenu (Android)

I have a ListView that will allow the user to long-press an item to get a context menu. The problem I’m having is in determining which ListItem they long-pressed. I’ve tried doing this: myListView.setOnCreateContextMenuListener(new OnCreateContextMenuListener() { @Override public void onCreateContextMenu(ContextMenu menu, final View v, ContextMenuInfo menuInfo) { menu.add(“Make Toast”) .setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean … Read more

Using a ListView to create a settings screen in Android?

I’m developing my first Android application, and I’d like to create a settings screen. I’d like the screen to have a similar look-and-feel as the native phone-settings screens and the native “create/edit alarm” screen. Thus with different kinds of (statically defined) items vertically stacked with a thin line between them. How do I define such … Read more