Android LinearLayout orientation

I have just spent an hour or so just to figure out why in the world that my custom dialog view only shows the first element. So, as you might have guessed, I screwed up the root LinearLayout orientation. I didn’t specify any, so it assumed the default value which is horizontal. And that’s why I only see my first element in the custom dialog. I know it sounds silly, but once your deadline is tomorrow morning and it’s already half past one, you might just encounter this little bummer! Hence I decided to make this short post to remind anyone who had similar trouble.

http://developer.android.com/reference/android/widget/LinearLayout.html#attr_android:orientation

 

Anyway, my custom dialog layout file is as follow:

<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:orientation=”vertical”>

<EditText
android:id=”@+id/text1″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”/>

<Spinner
android:id=”@+id/spinner1″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content” />

<Spinner
android:id=”@+id/spinner2″
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”/>

</LinearLayout>

 

And to create the custom alert dialog, I use the setView method as follow:

LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.close_job_dialog, null);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setView(view);

 

Leave a Comment

Your email address will not be published. Required fields are marked *