Set AlertDialog with Open Keyboard

4

I have the following problem I have an AlertDialog

Whenthekeyboardopens,thedialoggoesup,butpartofthedialogishidden.Itdoesnotadjusttheheightasthekeyboard

DialogXML:

<ScrollViewxmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    <LinearLayout 
                  android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content"
                  android:id="@+id/root_view"
                  android:layout_marginTop="@dimen/activity_vertical_margin"
                  android:layout_marginBottom="@dimen/activity_vertical_margin"
                  android:layout_marginLeft="@dimen/activity_horizontal_margin"
                  android:layout_marginRight="@dimen/activity_horizontal_margin" >

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="16sp"
                android:id="@+id/txtCliente"
                android:text="Cliente : XXXXXXXXXXXXXXXXX" />

        <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="16sp"
                android:id="@+id/txtData"
                android:layout_marginTop="3dp"
                android:text="Data : XX/YY/ZZZZ hh:MM:ss" />



        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:gravity="center_vertical">
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textSize="16sp"
                    android:text="Motivo" />

            <Spinner
                    android:layout_marginLeft="10dp"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/spinner"/>
        </LinearLayout>

        <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="20dp"
                android:lines="3"
                android:maxLength="200"
                android:id="@+id/txtObs"
                android:layout_gravity="center_horizontal"/>


    </LinearLayout>

</ScrollView>

Code that generates AlertDialog

LayoutInflater inflater = LayoutInflater.from(mContext);
View dialog_layout = inflater.inflate(R.layout.dialog_motivonaoatendimento, null);

AlertDialog.Builder db = new AlertDialog.Builder(mContext);

db.setView(dialog_layout);
db.setTitle("Não Atendimento");
db.setPositiveButton("Confirmar", new
        DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            }
        });

db.setNegativeButton("Cancelar", null);

final AlertDialog alertDialog = db.create();
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

db.show();

One note I noticed, it seems like scrollview does not work. In some tests I saw that the "first" layout does not comply, and scrollview forces you to put the layout as "parent".

I do not know if this could be the cause of the problem ..

Thanks for your attention.

    
asked by anonymous 29.09.2016 / 18:49

1 answer

4

If EditText is within your Dialog , this will happen. One possible solution is you set InputType of your EditText . This will allow you to use the event of your keyboard, where clicking the DONE button will disappear, showing the complete dialog with the appropriate buttons. See:

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:lines="3"
android:maxLength="200"
android:id="@+id/txtObs"
android:layout_gravity="center_horizontal"
android:inputType="text"/>

Image

Seesomeexampleshereat article about inputType (en) .

Details

29.09.2016 / 19:02