无法设置编辑文本?来自一个片段中的对话框的问题-奇怪-Android Java
我遇到了一个我以前从未遇到过的问题。我有一个无法设置编辑文本?来自一个片段中的对话框的问题-奇怪-Android Java,java,android,fragment,Java,Android,Fragment,我遇到了一个我以前从未遇到过的问题。我有一个片段,包含一个按钮。此按钮(ViewBookingButton)显示一个弹出对话框。当对话框打开时,我想在EditText(AllBooking)中设置一个字符串。不幸的是,它崩溃并显示NullPointerExecption。出什么事了?这是我的密码: ViewBookingButton.setOnClickListener(new OnClickListener() { @Override public void onClick(
片段
,包含一个按钮。此按钮(ViewBookingButton
)显示一个弹出对话框。当对话框打开时,我想在EditText
(AllBooking
)中设置一个字符串。不幸的是,它崩溃并显示NullPointerExecption
。出什么事了?这是我的密码:
ViewBookingButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
AlertDialog.Builder ViewBookingHelpBuilder = new AlertDialog.Builder(getActivity());
ViewBookingHelpBuilder.setTitle("view booking:");
LayoutInflater inflater = getActivity().getLayoutInflater();
View DialogLayout = inflater.inflate(R.layout.view_booking, null);
ViewBookingHelpBuilder.setView(DialogLayout);
TextView AllBooking = (TextView)view.findViewById(R.id.AllBooking);
AllBooking.setText("Hello World");//WHEN I REMOVE THIS THE DIALOG WORKS
ViewBookingHelpBuilder.setPositiveButton("Done", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which)
{
}
});
AlertDialog helpDialog = ViewBookingHelpBuilder.create();
helpDialog.show();
}
});
改变这个
TextView AllBooking = (TextView)view.findViewById(R.id.AllBooking);
到
TextView
属于膨胀布局,findViewById在当前视图层次结构中查找该视图。非常感谢@Raghunandan
TextView AllBooking = (TextView)DialogLayout.findViewById(R.id.AllBooking);