mercredi 11 mai 2016

How to get id from dynamically added checkbox and them value

I want to get value for dynamically added CheckBox but when i want to see if one of my checkBox.isChecked(); it only respond when i check the last checkbox created ! Here is my container.

for (String answer : multiMap.get(questionFromMultiMap))
        {

            i++;
            et_button = (CheckBox) getLayoutInflater().inflate(R.layout.numberofchoices, null);
            et_button.setText(answer);
            et_button.setId(i);
            container.addView(et_button);
            listOfChoice.add(answer);


        }

I want to check it's checked like that :

btnCorrect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

         if (et_button.isChecked()){
             System.out.println(et_button.getId());
         }else{
             System.out.println("pouet");
         }

        }
    });

Didn't find right answer on google ! Thanks for help




Aucun commentaire:

Enregistrer un commentaire