[英]How to pass the selected items (multiple items in my recyclerview) values from the adapter to the fragment in android using java
[英]how to pass values from List View Adapter to fragment in android
我想將相同的值從適配器傳遞到片段,然后以以下方式發送它:
Fragment fr = new Fragment
fr.deleteMothod(Position);
當我調用上述代碼時,它正在創建Fragment的新實例,因此我不訪問fragment的值。 如何使用片段的舊實例。
您可以像這樣修改片段的構造函數:
public static DetailsFragment newInstance(String selection, String[] selectionArgs) {
DetailsFragment detailsFragment = new DetailsFragment();
Bundle args = new Bundle();
args.putString("selection", selection);
args.putStringArray("selectionArgs", selectionArgs);
detailsFragment.setArguments(args);
return detailsFragment;
}
但是,如果使用接口,則有更好的方法。
您應該通過ID或標簽從“片段管理器”中檢索您的片段,然后在其上調用方法。 這些是官方文檔http://developer.android.com/training/basics/fragments/communicating.html#Deliver
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.