我有一个自定义 AlertDialog.Builder,但我无法访问 EditText。
这是我的默认课程;
AlertDialog.Builder Builder = new AlertDialog.Builder(this);
LayoutInflater Inflater = this.getLayoutInflater();
View AddCategory = Inflater.inflate(R.layout.category_new, null);
final EditText etCategoryName = (EditText) AddCategory.findViewById(R.id.btnAddCategory);
Builder.setView(AddCategory)
.setTitle("Add Category")
.setPositiveButton("ADD", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Time Today = new Time(Time.getCurrentTimezone());
Today.setToNow();
//This code has error !...
String CategoryName = etCategoryName.getText().toString();
}
})
.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
Builder.show();
此字符串 CategoryName = etCategoryName.getText().toString();
这是我的 Costum AlertDialog 布局;
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="60dp" >
<TextView
android:id="@+id/tvAddCategoryName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:text="@string/AddCategoryName"
android:textColor="@color/White"
android:textAppearance="?android:attr/textAppearanceMedium" />
<EditText
android:id="@+id/etAddCategoryName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/tvAddCategoryName"
android:layout_alignBottom="@+id/tvAddCategoryName"
android:layout_toRightOf="@+id/tvAddCategoryName"
android:layout_marginLeft="20dp"
android:hint="@string/CategoryName"
android:ems="10" >
<requestFocus />
</EditText>
请帮我 ...