[英]how to intent to the exact position of the recyclerview when back button clicked
There is a list of items in an activity, when I click any activity, it gets into the detailed activity. 活动中有一个项目列表,当我单击任何活动时,它将进入详细活动。 When back button is clicked from the detailed activity it goes to the top of the list.
从详细活动中单击“后退”按钮时,它将转到列表的顶部。 I want it to go to the previous scroll position.
我希望它转到上一个滚动位置。
this is the onBackPressed() of the detailed activity 这是详细活动的onBackPressed()
@Override
public void onBackPressed()
{
Intent intent = new Intent(this,MainActivity.class);
intent.putExtra("index",NAV_INDEX_MY_GROUPS);
intent.putExtra("tag",TAG_MY_GROUPS);
startActivity(intent);
finish();
}
how to intent back to the previous scroll position of the list activity 如何意图回到列表活动的上一个滚动位置
将数据绑定到recyclerview
后,使用以下代码
mRecyclerView.smoothScrollToPosition("your_index");
If the MainActivity
is already on your back stack, then you don't want to use startActivity
to start a second copy of it. 如果
MainActivity
已经在您的后备堆栈上,则您不想使用startActivity
启动它的第二个副本。 The default onBackPressed()
is enough to go back to the previous activity already. 默认的
onBackPressed()
足以返回到先前的活动。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.