我的应用程序中有一个对话框片段,我正在调用它 -
dialog=new
FragmentActivity.dfragment(this);
getFragmentManager().findFragmentById(R.id.fragment3).getView()
.findViewById(R.id.btn1)
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.show(getFragmentManager(), "Dialog");
System.out.println(getFragmentManager().findFragmentByTag("Dialog").getTag());
// gives null pointer exception
}
});
// 对话框片段类。
public static class dfragment extends DialogFragment {
public dfragment(DialogDisplayed dd) {
super();
this.dd = dd;
Bundle b = new Bundle();
b.putBoolean("Value", true);
setArguments(b);
}
DialogDisplayed dd;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
getDialog().setTitle("DIALOG FRAGMENT");
View v = inflater.inflate(R.layout.dialog_layout, container);
v.findViewById(R.id.diss).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(), "Setting the bundle",
Toast.LENGTH_SHORT).show();
dismiss();
dd.onDialogClicked();
}
});
return v;
}
}
我相信它无法通过标签“对话框”找到片段,即使文档说它将它添加到 FragManager。我想知道为什么它会例外谢谢