From MainActivity:
public class MainActivity extends ListActivity implements AdapterView.OnItemLongClickListener {
private DataSourceSql mDataSourceSql;
protected ArrayList<String> mProfileNames;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDataSourceSql = new DataSourceSql(MainActivity.this);
mNames = new ArrayList<String>();
//this part here
ListView lv = (ListView) findViewById(android.R.id.list);
lv.setLongClickable(true);
}
The id of the ListView
in this case is set in the XML as android:id="@android:id/list"
.
And then later on in the same activity:
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Toast.makeText(this, mNames.get(position), Toast.LENGTH_SHORT).show();
}
@Override
public boolean onItemLongClick(AdapterView<?> l, View v, final int position, long id) {
Toast.makeText(this, "long clicked: " + mNames.get(position), Toast.LENGTH_LONG).show();
return true;
}
But when I long-press an item in the list, the only thing that triggers is onListItemClick
. I never get the message with the long click.