主要活動
-一個片段
-B 片段
-C 片段(有 3 個子片段)
-一個片段
-b 片段
-c 片段
這就是我的專案的組織方式。
RecyclerView存在于a,b,c Fragment中,RecyclerView中生成的item數量在a,b,c Fragment的textView中表示。
為了一目了然地查看 a,b,c Fragment 中 RecyclerView 專案的數量,我想將整數值傳遞給 A Fragment。
adapter = new TestAdapter();
recyclerView_kor.setAdapter(adapter);
ArrayList<TestInfo> result = callback.selectAll();
//callback.SelectAll() is a lookup of database cumulative values.
adapter.setItems(result);
String countMath = result.size() "times";
textView_kor.setText(countMath);
AFragment Afragment = new AFragment();
Bundle bundle = new Bundle();
bundle.putString("textView_Math", countMath);
Afragment.setArguments(bundle);
我試圖通過將鍵值和要傳遞給它的字串并在 A Fragment 中輸入鍵值來接收該值
Math_practicenumber_textVIew = rootView.findViewById(R.id.Math_practicenumber_textVIew);
Math_practicenumber_textVIew.setText(getArguments().getString("textView_Math"));
但它沒有用......我如何修復和弦?
uj5u.com熱心網友回復:
假設這是你的片段 B
val bundle = Bundle()
bundle.putString("textView_Math", countMath)
findNavController(R.id.nav_host_fragment).navigate(
R.id.fragmentA,
bundle
)
在你的 FragmentA
私有變數文本名稱:字串 =“”
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
arguments?.let {
textName = it.getString("textView_Math")
}
}
最后
Math_practicenumber_textVIew.text=textName
uj5u.com熱心網友回復:
使用 ViewModel 在 Fragment 之間進行通信,但請注意視圖模型需要共享 ViewModel。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/421234.html
標籤:
下一篇:微服務架構 | 4. 服務呼叫
