我有一个习俗方言箱。 当点击“K”时,我希望从EditText的田地获得案文。 然而,它 throw倒了一种无效的例外。
法典:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.dialog_delivered, (ViewGroup)findViewById(R.id.llDeliveredDialog));
builder.setMessage("Dialog message");
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
final EditText text = (EditText)findViewById(R.id.etGivenTo);
String value = text.getText().toString();
}
});
builder.setCancelable(false);
builder.setView(layout);
builder.show();
XML Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/llDeliveredDialog"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/etGivenTo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:ems="10" >
<requestFocus />
</EditText>
</LinearLayout>
任何帮助都会受到高度赞赏。