我使用对话框片段来显示活动中的对话框。没有错误,我可以在logcat中找到日志,但在运行应用程序时看不到对话框。我不知道有什么问题。
这是我的活动代码:
btnEventRegister.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getSupportFragmentManager();
DialogPlusEvent dialogPlusEvent = new DialogPlusEvent();
Bundle bundle = new Bundle();
bundle.putString("eventPlaceName", eventPlaceName);
bundle.putLong("currentUserDistance", currentUserDistance);
dialogPlusEvent.setArguments(bundle);
dialogPlusEvent.show(fragmentManager, "DialogPlusEvent");
Log.d("Dialog Fragment", "Working");
}
});
对话框片段代码:
public class DialogPlusEvent extends DialogFragment implements View.OnClickListener{
TextView dpeTvPlaceName, dpeStar, dpeTvMyDistance;
private String dpePlaceName;
private Long dpeMyDistance;
private Button dpeBtnOkay;
public static DialogPlusEvent getInstance() {
DialogPlusEvent dialogPlusEvent = new DialogPlusEvent();
return dialogPlusEvent;
}
@Nullable
public View OnCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_plus_event, container);
SharedPreferences sharedPreferences = this.getContext().getSharedPreferences("file", Context.MODE_PRIVATE);
currentPage = sharedPreferences.getString("currentPage", "");
/.../
Bundle bundle = getArguments();
dpePlaceName = bundle.getString("eventPlaceName");
dpeMyDistance = bundle.getLong("currentUserDistance");
dpeBtnOkay = view.findViewById(R.id.dpeBtnOkay);
dpeBtnOkay.setOnClickListener(this);
setCancelable(false);
return view;
}
public void onClick(View view) {
dismiss();
}
}
2条答案
按热度按时间k3fezbri1#
@谢金是对的。您没有正确实现oncreateview方法。
我运行了你提供的代码,它工作得很好,我可以看到对话框,所以我认为问题不在这段代码。
wa7juj8i2#
你在执行
onCreateView
方法把方法从
OnCreateView
至onCreateView
如下所示: