0

i have some problem with my application. In my App i have Main activity and this activity contain some fragment. In one of this fragments i have a recyclerview which have some items and i set onclicklistener for each item of recyclerview in adapter and when any item clicked i start second activity that show the clicked item with more details on it. so, i have one favorite button in my recyclerview for each item and also i have this favorite button on second activity. how i can do something when the favorite button selected in second activity and then this activiy finished when recyclerview showed again favorite button on recyclerview item will be changed.

In other case i want to start an activity from recyclerview adapter and if in started activity favorite button pressed, recyclerview item favorite button will be pressed after activity finished.

I used startActivityForResult but i don't know how to use it and even this will work or not. because if i use this it will return data to my Main Activity then i should send data to my fragment and after that send data from fragment to my adapter and i don't know this will work or not and even i don't know how to change my recyclerview item favorite button state after i receive data.

Should i use interface?

What is the solution?

here is my adapter code:

  @Override
    public void onClick(View view) {
        show_ads_getter = show_ads_list.get(getLayoutPosition());
        Intent intent = new Intent(view.getContext(), ShowAdsDetailsActivity.class);
        intent.putExtra("ads_id", show_ads_getter.getId());
        ((Activity) context).startActivityForResult(intent, 1);
        if (favorite_state.equals("change")){
            if (favorite_button.getVisibility() == View.VISIBLE){
                favorite_button.setVisibility(View.GONE);
                not_favorite_button.setVisibility(View.VISIBLE);
            } else {
                favorite_button.setVisibility(View.VISIBLE);
                not_favorite_button.setVisibility(View.GONE);
            }
        }
    }
}
Hexmaster
  • 3
  • 2
  • 2
    Does this answer your question? [How to manage startActivityForResult on Android?](https://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android) – grrigore Dec 10 '19 at 19:45
  • `startActivityForResult` is the right way to go but you've used it wrong. What @grrigore provides should be the correct version for you. – Wei WANG Dec 11 '19 at 01:22

0 Answers0