Note that there are some explanatory texts on larger screens.

plurals
  1. POListView repeating selection
    primarykey
    data
    text
    <p>I'm trying to make a context menu for my listview, so when a user long press a row, the context menu shows up, and when the user chooses an option, the row gets selected. However a lot of rows are selected, it repeats the selection in pattern for other rows in the listview.</p> <p>The same happens when I simply click a row. IDK if it's a problem with view recycling, or what.</p> <p>How to solve both issues, since first is handled inside <code>onContextItemSelected(MenuItem item)</code> so I manage the row by manipulating the <code>MenuItem</code> object, and the second is handled in <code>AdapterView.OnItemClickListener</code>.</p> <p><strong>BTW, I'm using CursorAdapter to populate the ListView.</strong></p> <p>Thanks.</p> <p>Here is my code:</p> <pre><code>// Listener for the click on the items in the ListView mListViewListener = new AdapterView.OnItemClickListener() { // When the user clicks some item, the Activity that shows the available dates will be shown @Override public void onItemClick(AdapterView&lt;?&gt; adapterView, View view, int position, long arg3) { view.setBackgroundColor(0xff333333); } }; // Handle the LongClick on the row @Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.contact_options, menu); } @Override public boolean onContextItemSelected(MenuItem item) { AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); switch(item.getItemId()) { case R.id.context_menu_item: info.targetView.setBackgroundColor(0xff333333); default: return super.onContextItemSelected(item); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload