我有一個窗體的對話框,用戶輸入一些數據,我想獲取該數據,但是當我將數據記錄到查看它我什麼都沒有。我有一個對話框中的這種形式,但我無法獲得輸入框的值
public Dialog onCreateDialog (Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
final View view = inflater.inflate(R.layout.incident_form,null);
builder.setView(inflater.inflate(R.layout.incident_form,null)
.setPositiveButton("Submit", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id)
{
title = (EditText) view.findViewById(R.id.report_title);
recom = (EditText) view.findViewById(R.id.report_recommendation);
content = (EditText) view.findViewById(R.id.report_content);
titleString = title.getText().toString();
recomString = recom.getText().toString();
contentString = content.getText().toString();
submitForm(titleString,recomString,contentString);
dialog.cancel();
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
return builder.create();
}
當您使用自定義佈局時,請移除setNegativeButton和setPositivetiveButton。 –
爲什麼你包括你的佈局兩次? –
@PreetikaKaur感謝您指出這一點,我沒有注意到它。解決了這個問題 – lagfvu