i'm trying to update a row of my recyclerView basically there's an onclickListner in my RecyclerView's row and when it triggers this is what happens :
holder.FAVORITE.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// here i'm updating the object which is in selected row
realm.beginTransaction();
Channels channels = new Channels();
channels.setObjectId(holder.ID.getText().toString());
channels.setIsFavourite(false);
realm.copyToRealmOrUpdate(channels);
realm.commitTransaction();
int id = getResources().getIdentifier("drawable/" + "un_favorite", null, null); // here i'm setting image for row
holder.FAVORITE.setBackgroundResource(id);
// now we are done with updating our data but i'm having trouble to reflect this change on my Recyclerview
updateAdapter(isFavoriteActive); // this function is for updating recyclerView
}
});
///////////
public void updateAdapter (Boolean isFavoriteActive ){
ChannelsQueryRealm =
realm.where(Channels.class)
.equalTo("isFavourite", true)
.findAll(); // here i fetched the data that i want to put in my recyclerView
channelsIDArray.clear();
channelIsFavoriteArray.clear();
for (Channels channels : ChannelsQueryRealm) {
channelsIDArray.add(channels.getObjectId());
channelIsFavoriteArray.add(channels.getIsFavourite());
} // here i added new updated data in my array's
new Runnable() {
public void run() {
channelsAdapter.notifyDataSetChanged(); // and here i'm trying to reflect the change but its not working fine because the updated change is not reflecting correctly on desired row
}
};
}
if anybody knows how to do it correctly then please let me know
P.s. this question may sound like duplicate of others like this one but i tried there solution and nothing worked for me