lundi 15 janvier 2018

how to listen to a checkbox inside of multiply inflated layout?

So I have this code:

for (int i = 0;i<procedures.length;i++) {

        if (procedures[i].toLowerCase().contains(keyword.toLowerCase())) {

            view = inflater.inflate(R.layout.with_timer_instruction, null);
            timerTextView = (TextView) view.findViewById(R.id.timerTextView);
            timerTextView.setText(procedures[i]);
            instructions.addView(view);

        } else {

            view = inflater.inflate(R.layout.simple_instruction, null);
            simpleTextView = (TextView) view.findViewById(R.id.simpleTextView);
            simpleTextView.setText(procedures[i]);
            instructions.addView(view);

        }

        view.setTag(i);

    }

it basically inflates a layout depending if the string has the keyword in it, and these 2 layouts to be inflated has a checkbox in it. So, on the screen, there would be lots of checkBoxes, and I needed to listen to its check events.

I had an incomplete solution for this, I am stuck on it so I came for an advice how to do it in another way.

but if ever I was on the right track, my solution was I added android:onClick="checkBoxProcedure" in the layouts to be inflated, make my checkBoxProcedure method on the Activity's Java then depending on the tag it had it would do something, but it gives me an error:

Could not find method checkBoxProcedure(View) in a parent or ancestor Context for android:onClick attribute

are there anyways or how can I correct this? Thanks!




Aucun commentaire:

Enregistrer un commentaire