你好,我试图在屏幕上显示自定义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); –