[英]Can I call fragment's method from another fragment?
我有一個 fragmentA,我想用方法調用 fragmentB。
我添加了
myFragment.my_tag=1;
myFragment.dialogPersonalProfile();
轉換,認為它會起作用,但沒有。 你能建議我嗎?
new AlertDialog.Builder(getActivity())
.setView(getLayoutInflater().inflate(R.layout.baseinfo, null))
.setPositiveButton(R.string.fill_profile,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
AppCompatActivity activity = (AppCompatActivity) view.getContext();
ArtistProfileView myFragment = new ArtistProfileView();
myFragment.my_tag=1;
myFragment.dialogPersonalProfile();
activity.getSupportFragmentManager().beginTransaction()
.replace(((ViewGroup)(getView().getParent())).getId(), myFragment)
.commit();
}
}).show();
當用戶在 FragmentA 上並單擊按鈕時,它應該打開 FragmentB 的方法,在我的情況下是配置文件編輯。
您必須讓片段生命周期完成這項工作。
為 FragmentB(在本例中為 ArtistProfileView)設置一個參數,並使用它從 onCreateView 調用函數。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.