Monday 8 October 2018

Android code for scrollable alert dialog

Create your own layout.xml file containing a Text View under Scroll View. and set TextMessage in this Text View, Inflate this layout with your alert dialog box.

<ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/textmsg"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/hello" />

    </LinearLayout>
</ScrollView>




LayoutInflater inflater= LayoutInflater.from(this);
View view=inflater.inflate(R.layout.yourxmlfile, null);

TextView textview=(TextView)view.findViewById(R.id.textmsg);
textview.setText("Your really long message.");
final AlertDialog alertDialog = new AlertDialog.Builder(ctx).create();
        alertDialog.setTitle("Title");
        alertDialog.setView(view);
        alertDialog.setButton("OK", new DialogInterface.OnClickListener()
        {
            public void onClick(DialogInterface dialog, int which)
            {
                alertDialog.dismiss();
            }
        });
alertDialog.show();


No comments:

Post a Comment