dimanche 24 septembre 2017

Unable to "check" dynamically created checkboxes - Android

I'm trying to make dynamically created checkboxes depending on the item selected in my 'color' spinner.

For example: if I select "red" on my spinner, the following checkboxes will be created: Apple [ ], Strawberry [ ], Cherry [ ]. If I select "yellow" from teh spinner, the following checkboxes will be created: Banana [ ], Pineapple [ ].

My code works and displays the listed items correctly when I run it but why are my dynamically generated checkboxes "uncheckable" when I press on them? The little "checkmark" doesn't appear in the boxes at all.

private Fruits fruit = new Fruits();

final GridView gv = (GridView) findViewById(R.id.gv);
Spinner sp = (Spinner) findViewById(R.id.sp);

sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

   @Override
   public void onItemSelected(AdapterView<?> adapterView, View v, int pos, long l){

      String item = (String) adapterView.getItemAtPosition(pos);
      List<String> myList = fruit.getFruits(item);

      ArrayAdapter<String> adapter_1 = new ArrayAdapter<String>(Activity_1.this, android.R.layout.simple_list_item_multiple_choice, myList);
      gv.setAdapter(adapter_1);
   }




Aucun commentaire:

Enregistrer un commentaire