我在一些文本中有DialogFragment,我想在Fragment中打开它
对话片段第一
public class subscribe_dialog_frag extends DialogFragment {
@Override
@Nullable
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState){
super.onCreateView(inflater, container, savedInstanceState);
return inflater.inflate(R.layout.subscribe_dialog_fragment, container, false);
}
}
这是我的代码片段
public class Main4Fragment extends Fragment {
private ImageButton btn_money;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_main4, container, false);
btn_money = (ImageButton)view.findViewById(R.id.btn_momey);
btn_money.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Fragment subscribe_dialog_frag = new subscribe_dialog_frag();
FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
transaction.replace(R.id.btn_momey, subscribe_dialog_frag).commit();
}
});
return view;
}
}
我只是打开了dialogFragment。
可能吗??还是我做另一种方式?
1条答案
按热度按时间osh3o9ms1#
首先对类/变量使用命名约定...将对话框重命名为:
在Main 4Fragment调用中,类似于以下内容: