Activity 关闭时更新 RecyclerView 项目

Updating a RecyclerView item when Activity closed

我有一个 RecyclerView,用户可以在 recyclerview 布局上为球队加油或点击项目为比赛页面内的球队加油,我需要做的是更新第一个布局中的 recyclerview 加油栏曾经有用户进入完整比赛页面并为球队加油

first recyclerview layout iamge

Full Match Layout image

我需要创建某种将在

中激活的监听器
    @Override
public void onBackPressed() {
    super.onBackPressed();
    Log.d("posss", "onBackPressed:cheeredTeam:"+cheeredTeam);
    Log.d("posss", "onBackPressed:pos:" + pos);
    // Activite Listener with (recycler position , cheered team ) 
}

您需要在开始完整比赛时使用 startActivityForResult(Intent, requestCode) activity!然后,当用户 returns 到你的 RecyclerView 时,你会想在此之前插入 setResult(Intent) 。然后,在您的片段中创建 onActivityResult() 函数,它将通过 Intent 接收更新的信息。

在制作 onActivityResult 方法时也请看这个:onActivityResult is not being called in Fragment