Note that there are some explanatory texts on larger screens.

plurals
  1. POProgrammatically change listview so that it is checkable
    primarykey
    data
    text
    <p>I've made a decent effort to find a similar question and failed, so please forgive me if this is redundant pollution.</p> <p>I have a ListView and an ImageButton defined in the xml file "my_layout" corresponding to my Activity as follows:</p> <pre><code>&lt;ListView android:id="@+id/listViewItems" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="1" &gt;&lt;/ListView&gt; </code></pre> <p>and</p> <pre><code>&lt;ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/btn_delete_dark" android:id="@+id/buttonDelete" android:layout_weight="1"&gt; &lt;/ImageButton&gt; </code></pre> <p>I then populate the ListView programmatically in the onCreate() method of my Activity as follows:</p> <p>public class ViewItemsActivity extends Activity implements OnClickListener, OnItemClickListener{</p> <pre><code>ImageButton buttonDelete; ListView listViewItems; DatabaseHandler dbHandler; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.my_layout); buttonDeleteQuestion = (ImageButton) findViewById(R.id.buttonDelete); listViewQuestions = (ListView) findViewById(R.id.listViewItems); buttonDelete.setOnClickListener(this); //get data from sql table containing items dbHandler = new DatabaseHandler(this); String [] items = dbHandler.getItems(); //get data to populate ListView CustomAdapter adapter = new CustomAdapter(this, android.R.layout.simple_list_item_1, items); listViewItems.setAdapter(adapter); listViewItems.setOnItemClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.buttonDelete: listViewItems.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE); listViewItems.setItemChecked(0, true); break; //other cases are irrelevant } } @Override public void onItemClick(AdapterView&lt;?&gt; parent, View v, int pos, long id) { // TODO Auto-generated method stub //non relevant code } </code></pre> <p>}</p> <p>Everything works as it should except that I want the ListView to change, in appearance and functionality, as a result of clicking buttonDelete, so that it displays checkmarks to the right of each row which can be checked by clicking on them.</p> <p>It was my understanding that setChoiceMode(ListView.MULTIPLE_CHOICE) and setItemChecked(i,true) would have this effect, but clearly I've missed something as it does not.</p> <p>I am quite new to android and so it is possible that I've wasted someone's time with trivialities, for which I apologize.</p> <p>Thank you very much.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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