你好,我試圖在屏幕上顯示自定義AlertDialog。 我正在向對話框中添加布局,此佈局包含兩個TextView,一個RatingBar和一個EditText。android.view.InflateException - 錯誤膨脹類android.widget.EditText
當我試圖彈出我得到這個例外對話框:
E/AndroidRuntime(12989): android.view.InflateException:二進制XML文件行#25:錯誤 充氣類的android .widget.EditText
重要的一點是在Android 2.3.x版本的設備出現這個錯誤,它適用於Android 4.x的偉大
dialog_comment.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RatingBar
android:id="@+id/DialogCommentRatingBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:stepSize="1" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/DialogCommentRatingBar"
android:text="Yorumunuz"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/DialogCommentComment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView2"
android:background="?android:attr/editTextBackground"
android:ems="10"
android:gravity="top"
android:inputType="textMultiLine" >
</EditText>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Oyunuz"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
CommentDialog.java
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater=getActivity().getLayoutInflater();
final View view=inflater.inflate(R.layout.dialog_comment, null);
final RatingBar rating=(RatingBar)view.findViewById(R.id.DialogCommentRatingBar);
final EditText comment=(EditText)view.findViewById(R.id.DialogCommentComment);
AlertDialog.Builder builder=new AlertDialog.Builder(getActivity());
builder.setView(view);
builder.setTitle("Enter Your Comment!");
return builder.create();
}
如何顯示AlertDialog
FragmentManager fm = getSupportFragmentManager();
CommentDialog commentDialog = new CommentDialog();
commentDialog.show(fm, "fragment_comment_dialog");
嘗試這種情況:LayoutInflater INF =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);也許它有幫助。其實試圖調試。我認爲你給null視圖。 – 2013-07-22 08:22:11
@fobus嘗試刪除從EditText上的背景屬性,看看它是否有什麼差別 – Blackbelt
刪除此行 機器人:背景=「機器人:ATTR/editTextBackground」從&的EditText更新該行最終視圖視圖= inflater.inflate(R .layout.dialog_comment,null,false); –