Search code examples
androidandroid-layoutscrollview

Can't edit EditText


I'm having a weird problem i've never encountered.

I'm building quite a complex layout for an activity. My only issue is, i can't edit the edittexts in any way. I've tried both with the emulator and the real device. To be more specific, when i click on the edittext, the cursor appears for a very short moment, then disappears. The keyboard never shows up. In the java code i didn't do anything with the EditTexts (not even called them yet).

Any idea what could be the issue?

I've already tried many solutions from other posts, with no luck.

Attaching the xml code here:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          xmlns:tools="http://schemas.android.com/tools"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="center"
          tools:context=".Iscrizione"
          android:orientation="vertical">

    <ScrollView
        android:id="@+id/valutazione_sv_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="15dp">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_gravity="center_horizontal"
            android:descendantFocusability="blocksDescendants">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:text="@string/valutazione_1"
                android:textAlignment="center"
                android:textSize="16sp"/>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:weightSum="100">

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="50">

                        <android.support.v7.widget.AppCompatCheckBox
                            android:id="@+id/valutazione_cb_1_1"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"/>

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/valutazione_1_1"/>

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="50">

                        <android.support.v7.widget.AppCompatCheckBox
                            android:id="@+id/valutazione_cb_1_2"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"/>

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/valutazione_1_2"/>

                    </LinearLayout>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:weightSum="100">

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="50">

                        <android.support.v7.widget.AppCompatCheckBox
                            android:id="@+id/valutazione_cb_1_3"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"/>

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/valutazione_1_3"/>

                    </LinearLayout>

                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="50">

                        <android.support.v7.widget.AppCompatCheckBox
                            android:id="@+id/valutazione_cb_1_4"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"/>

                        <TextView
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:text="@string/valutazione_1_4"/>

                    </LinearLayout>

                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <android.support.v7.widget.AppCompatCheckBox
                        android:id="@+id/valutazione_cb_1_5"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"/>

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="@string/valutazione_1_5"/>

                    <EditText
                        android:id="@+id/valutazione_et_1_5"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_marginRight="10dp"
                        android:cursorVisible="true"
                        android:ems="10"
                        android:focusable="true"
                        android:focusableInTouchMode="true"/>

                </LinearLayout>

            </LinearLayout>

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="15dp"
                android:text="@string/valutazione_2"
                android:textAlignment="center"
                android:textSize="16sp"/>

            <EditText
                android:id="@+id/valutazione_et_2"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginLeft="15dp"
                android:layout_marginRight="15dp"
                android:maxLength="2000"
                android:maxLines="4"/>

            <Button
                android:id="@+id/valutazione_puls_prosegui1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginBottom="20dp"
                android:layout_marginTop="30dp"
                android:layout_marginStart="10dp"
                android:layout_marginEnd="10dp"
                android:background="@color/pulsanti"
                android:text="@string/pulsavanti"/>

</LinearLayout>

</ScrollView>

</LinearLayout>

Solution

  • Remove android:descendantFocusability="blocksDescendants" from your LinearLayout it will work

    "blocksDescendants"

    The ViewGroup will block its descendants from | receiving focus.

    Try this

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    
        <ScrollView
            android:id="@+id/valutazione_sv_1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:padding="15dp">
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:layout_gravity="center_horizontal"
                >
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="15dp"
                    android:text="valutazione_1"
                    android:textAlignment="center"
                    android:textSize="16sp"/>
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="vertical">
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:weightSum="100">
    
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="50">
    
                            <android.support.v7.widget.AppCompatCheckBox
                                android:id="@+id/valutazione_cb_1_1"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"/>
    
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="valutazione_1_1"/>
    
                        </LinearLayout>
    
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="50">
    
                            <android.support.v7.widget.AppCompatCheckBox
                                android:id="@+id/valutazione_cb_1_2"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"/>
    
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="valutazione_1_2"/>
    
                        </LinearLayout>
    
                    </LinearLayout>
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal"
                        android:weightSum="100">
    
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="50">
    
                            <android.support.v7.widget.AppCompatCheckBox
                                android:id="@+id/valutazione_cb_1_3"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"/>
    
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="valutazione_1_3"/>
    
                        </LinearLayout>
    
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            android:layout_weight="50">
    
                            <android.support.v7.widget.AppCompatCheckBox
                                android:id="@+id/valutazione_cb_1_4"
                                android:layout_width="wrap_content"
                                android:layout_height="wrap_content"/>
    
                            <TextView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:text="valutazione_1_4"/>
    
                        </LinearLayout>
    
                    </LinearLayout>
    
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">
    
                        <android.support.v7.widget.AppCompatCheckBox
                            android:id="@+id/valutazione_cb_1_5"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"/>
    
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:text="valutazione_1_5"/>
    
                        <EditText
                            android:id="@+id/valutazione_et_1_5"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_marginLeft="10dp"
                            android:layout_marginRight="10dp"
                            android:cursorVisible="true"
                            android:ems="10"
                            android:focusable="true"
                            android:focusableInTouchMode="true"/>
    
                    </LinearLayout>
    
                </LinearLayout>
    
                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:padding="15dp"
                    android:text="valutazione_2"
                    android:textAlignment="center"
                    android:textSize="16sp"/>
    
                <EditText
                    android:id="@+id/valutazione_et_2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="15dp"
                    android:layout_marginRight="15dp"
                    android:maxLength="2000"
                    android:maxLines="4"/>
    
                <Button
                    android:id="@+id/valutazione_puls_prosegui1"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginBottom="20dp"
                    android:layout_marginTop="30dp"
                    android:layout_marginStart="10dp"
                    android:layout_marginEnd="10dp"
                    android:text="pulsavanti"/>
    
            </LinearLayout>
    
        </ScrollView>
    
    </LinearLayout>