簡體   English   中英

單擊后退按鈕時如何確定recyclerview的確切位置

[英]how to intent to the exact position of the recyclerview when back button clicked

活動中有一個項目列表,當我單擊任何活動時,它將進入詳細活動。 從詳細活動中單擊“后退”按鈕時,它將轉到列表的頂部。 我希望它轉到上一個滾動位置。

這是詳細活動的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();
}

如何意圖回到列表活動的上一個滾動位置

將數據綁定到recyclerview后,使用以下代碼

mRecyclerView.smoothScrollToPosition("your_index");

如果MainActivity已經在您的后備堆棧上,則您不想使用startActivity啟動它的第二個副本。 默認的onBackPressed()足以返回到先前的活動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM