How to make scrolling of the contents of AlertDialog?

Added, not working

header.setScroller(new Scroller(getActivity())); header.setVerticalScrollBarEnabled(true); header.setMovementMethod(new ScrollingMovementMethod()); 

Code:

 private void setListeners() { view.findViewById(R.id.create_new_space).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { LayoutInflater layoutInflater = LayoutInflater.from(getActivity()); View promptView = layoutInflater.inflate(R.layout.onboarding_dialog_create_space, null); TextView header = (TextView) promptView.findViewById(R.id.header_dialog); header.setText(type + " name"); AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity()); alertDialogBuilder.setView(promptView); EditText newName = (EditText) promptView.findViewById(R.id.input_name); alertDialogBuilder.setCancelable(false) .setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { if (newName.getText().toString().trim().length() != 0 && mStorage != null) { mStorage.open(); mStorage.writeSpaces(type, newName.getText().toString().trim(), null); mStorage.close(); invoker.callYourSpace(newName.getText().toString().trim(), type); } dialog.cancel(); } }) .setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); AlertDialog alert = alertDialogBuilder.create(); alert.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE); alert.show(); } }); } 

XML

 <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="10dp"> <com.firstalert.onelink.utils.GothamTextView android:id="@+id/header_dialog" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:text="Home Name" android:textAlignment="center" android:textColor="@color/onelink_dark_blue" android:textSize="20sp" android:textStyle="bold" /> <com.firstalert.onelink.utils.GothamTextView android:id="@+id/textView2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="10dp" android:text="This is the space where the alarm is installed" android:textAlignment="center" android:textColor="@color/onelink_dark_blue" android:textSize="16sp" /> <EditText android:id="@+id/input_name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:layout_weight="0.37" android:background="@drawable/rounded_edittext" android:hint="Name" android:padding="10dp" android:paddingLeft="7dp" android:paddingRight="7dp" android:textAppearance="?android:attr/textAppearanceSmall" android:textColor="@color/onelink_dark_blue" android:textColorLink="@color/onelink_dark_blue" android:maxLines="1"/> 

    1 answer 1

    Wrap everything you have onboarding_dialog_create_space.xml in a ScrollView . Here is an example implementation:

     <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true" > <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> 

    UPD # 1 Why do I need the android:fillViewport ?

    Our ScrollView in layout_height fill_parent . This is not at all what you need when we work with ScrollView . What is the use of ScrollView if its content is the same in height? In this case, we have nothing to scroll. To solve this problem, you can use the android:fillViewport . When it is set to true , the contents of the ScrollView will stretch to its full height, but only if it fits. If the content does not fit in height - the behavior remains standard, the view can be scrolled as usual.

    • It still does not scroll, added a screenshot. - user233428
    • @ user233428 better add onboarding_dialog_create_space.xml markup file listing - Lex Hobbit
    • added listing - user233428
    • @ user233428 add to ScrollView android:fillViewport="true" - Lex Hobbit
    • one
      it worked, thank you very much - user233428