Android - How do i make this alert dialog scrollable?

ashu picture ashu · Jun 6, 2013 · Viewed 56.1k times · Source

I am a beginner in android and making my first android app. my 'About' menu item, when clicked shows an AlertDialog with a really long message. I have been trying different methods to make it scrollable but I couldn't. I have tried reading different questions on StackOverflow but they didn't work for me. Here is my AlertDialog code.

AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);  
alertDialog.setTitle("Title");  
alertDialog.setMessage("Here is a really long message.");  
alertDialog.setButton("OK", null);  
AlertDialog alert = alertDialog.create();
alert.show();

Can anybody explain to me in detail how to make it scrollable? Any help or suggestions would be appreciated!

Answer

blganesh101 picture blganesh101 · Jun 6, 2013

This solution is take from this post.

In order for a view to scrollable, it must be nested inside of a ScrollView container:

<ScrollView>
    <LinearLayout android:orientation="vertical"
            android:scrollbars="vertical"
            android:scrollbarAlwaysDrawVerticalTrack="true">
        <TextView />
        <Button />
    </LinearLayout>
</ScrollView>

Note that a ScrollView container can only have one child layout view. It is not possible, for example, to place a TextView and Button in a ScrollView without the LinearLayout.