1

I have a card view in which I included a text view and a checkbox , I tried some ways to work it out but I didn't get there, My issue is that I want to use the checkbox of card view and set it onclick but to be used on my Mainactivity, because after putting it onclick, I want to execute some piece of code,is there any way to do that, thank you

Willie Cheng
  • 7,679
  • 13
  • 55
  • 68
Taki
  • 3,290
  • 1
  • 16
  • 41
  • You are using wrong listener. Take a look at this https://stackoverflow.com/questions/8386832/android-checkbox-listener – Jivtesh Chahal Jul 16 '19 at 00:24
  • yes i corrected that but still dosnt solve my issue, i want to put checkbox OnCheckedChangeListener but that to be done on my main activity , since i m using cardview , i can only set it in my adapter class , usually when we want to put something onclick from adapter ,we use interface , is there way to put the checkbox of my cardview OnCheckedChangeListener in my main activity thank you mate – Taki Jul 16 '19 at 00:40

1 Answers1

0

You can use OnCheckedChangeListener only in adapter as it will apply to all the rows in the card view. Can you share your adapter and main activity code So I can have a broader view at your problem.

  • Well the reason why i want to apply OnChckedChangeListener because i want trigger a notification after the click . this is my adapter https://pastebin.com/yQH0b3gP – Taki Jul 16 '19 at 00:58
  • The reason why i need a check box , is because i m making a premier league app , so in the settings section , there is teams names along with check box for each team name , so if the user checks it , he ll be notified with notifcation to be triggered using broadcast receiver reminding them that their team plays a game that day – Taki Jul 16 '19 at 01:16
  • checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { //check boolean here and send notification here if(mylisten != null ){ int position = getAdapterPosition(); if(position != RecyclerView.NO_POSITION){ mylisten.checkboxclick(isChecked); } } } }); – Jivtesh Chahal Jul 16 '19 at 01:32
  • Thank you for the anwser , i totally understood what you sent to me , and i could easily apply it , just one more thing please , in my activity , i have some data that i retreived from api , which i want to pass to the notification as well to pass the team games , and games dates to be shown for the user in notification , what can i do about that if i have to use notification in adapter , this is my piece of code for that https://pastebin.com/5ZZPFCEt thank you – Taki Jul 16 '19 at 01:46
  • add this data into a list and pass it through the adapter. public spinneradapter(List arrayList, List apiDataList){ this.arrayList = arrayList; } When you set adapter pass this list in it. Accept my answer bu clicking on tick button if you like my answer. – Jivtesh Chahal Jul 16 '19 at 02:00