我在我的列表视图活动布局顶部显示用户输入的自定义对话框。但是当我尝试在 onCreateDialog() 方法中引用编辑文本时,它总是空白。以下是我的代码,如果有人能指出我做错的地方,不胜感激 -
public class QuestionDialog extends DialogFragment
{
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
// Get the layout inflater
LayoutInflater inflater = getActivity().getLayoutInflater();
// Inflate and set the layout for the dialog
final View v =inflater.inflate(R.layout.ques_dialog,null);
builder.setView(inflater.inflate(R.layout.ques_dialog, null))
.setTitle("Title Message!")
.setCancelable(true)
.setPositiveButton("GO", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int whichButton)
{
EditText et1 = (EditText)v.findViewById(R.id.et1);
// here not able to get the data from edit text
String s1 = et1.getText().toString().trim();
Log.d("debug","data -"+s1+" and length"+s1.length());
.... rest code goes here
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int whichButton)
{
..rest code goes here
}
});
return builder.create();
}
}