1

Hello I'm trying to show a custom AlertDialog on the screen. I'm inflating an layout into the dialog, this layout includes Two TextViews, one RatingBar and one EditText.

When I try to popup the dialog I'm getting this exception :

E/AndroidRuntime(12989): android.view.InflateException: Binary XML file line #25: Error inflating class android.widget.EditText

Important point is this error occurs on Android 2.3.x Devices, It works great on 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();

    }

How do I show AlertDialog

        FragmentManager fm = getSupportFragmentManager();
        CommentDialog commentDialog = new CommentDialog();
        commentDialog.show(fm, "fragment_comment_dialog");
5
  • Try this: LayoutInflater inf = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); Maybe it helps. Actually try to debug. I think you give null view. Commented Jul 22, 2013 at 8:22
  • 1
    @fobus try removing the background attribute from the EditText and see if it makes any difference Commented Jul 22, 2013 at 8:25
  • 1
    remove this line android:background="?android:attr/editTextBackground" from EditText & update this line final View view=inflater.inflate(R.layout.dialog_comment, null,false); Commented Jul 22, 2013 at 8:39
  • Yes removing background attribute fixed my problem. Commented Jul 22, 2013 at 9:20
  • did u solve this problem? Commented Aug 4, 2015 at 13:10

2 Answers 2

1

Replace

android:textAppearance="?android:attr/textAppearanceLarge"

with

android:textAppearance="@android:style/TextAppearance.Large"
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks but it didn't fix my problem.
0

Deleted my EditView (Plain Text text field), dropped another one into content_....xml and did not change any styling this time. Everything ran correctly with the default styling on the EditView.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.