0

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

Community
  • 1
  • 1
remy boys
  • 2,675
  • 5
  • 28
  • 57

2 Answers2

1

There is no execution call to your runnable object,follow this link

Community
  • 1
  • 1
Pavneet_Singh
  • 34,557
  • 5
  • 43
  • 59
-1

You have to run runnable instance

 Runnable runnable = new Runnable() {
            @Override
            public void run() {
                channelsAdapter.notifyDataSetChanged();
            }
        };
        new android.os.Handler().post(runnable);
Amit Padekar
  • 249
  • 1
  • 6
  • This gonna make a new handler every time. which is in this case can be many times so memory overhead – Pavneet_Singh Aug 13 '16 at 06:40
  • That was just hint to developer. He can create class level object of Handler. I have seen the answer you had posted on this question and deleted again. Before down voting please understand the case – Amit Padekar Aug 13 '16 at 06:41