Android Studio: нет контекстного меню для пустых EditTexts в ListView - нет возможности вставить в них - PullRequest
0 голосов
/ 11 апреля 2020

Я работаю в Android студии. У меня есть действие с ListView, и в ListView каждый элемент состоит из двух EditTexts, которые могут содержать или не содержать ничего в данный момент. Если эти EditTexts содержат текст, контекстное меню появляется так, как ожидается для копирования, вставьте et c., Но если они пусты, ничего не происходит - поэтому невозможно вставить что-либо в пустые EditTexts. Я попытался изменить атрибуты xml EditTexts и ListView всеми возможными способами (там много предложений), но ничего не изменилось. У меня есть EditText в моем MainActivity, у которого нет этой проблемы, поэтому я думаю, что он как-то связан с этими EditTexts, находящимися внутри ListView, но у меня закончились идеи о том, что еще можно попробовать. Есть адаптер для ListView, но код немного длинный - я буду рад опубликовать его (и любой другой код), если кто-то захочет разобраться в этом, и это полезно.

Вот где ListView определено:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:fitsSystemWindows="true"
    tools:context="com.dhadley1204.rubrica.ViewEditActivity">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/ve_toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
        app:layout_constraintTop_toTopOf="parent"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


    <ListView
        android:id="@+id/Entry"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:background="#FFFFEA"
        android:textIsSelectable="false"
        android:clickable="false"
        android:descendantFocusability="afterDescendants"
        android:divider="@android:color/holo_blue_dark"
        android:dividerHeight="1.0sp"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:longClickable="false"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/ve_toolbar"
        app:layout_constraintVertical_bias="0.0"/>
</androidx.constraintlayout.widget.ConstraintLayout>

And the two EditText ListView elements are defined here:

?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:descendantFocusability="afterDescendants">

<EditText
    android:id="@+id/tag"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="1dp"
    android:width="0dp"
    android:background="@null"
    android:ems="10"
    android:imeOptions="actionDone"
    android:focusable="true"
    android:clickable="true"
    android:longClickable="true"
    android:textIsSelectable="true"
    android:inputType="none"
    android:labelFor="@+id/tag"
    android:maxLines="1"
    android:singleLine="true"
    android:textColor="@android:color/holo_blue_dark"
    android:textSize="14sp" />

<EditText
    android:id="@+id/data"
    android:layout_below="@+id/tag"
    android:autofillHints="false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:width="0dp"
    android:background="@null"
    android:isScrollContainer="true"
    android:ems="10"
    android:clickable="true"
    android:textIsSelectable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:imeOptions="actionDone"
    android:inputType="textNoSuggestions"
    android:cursorVisible="true"
    android:selectAllOnFocus="false"
    android:singleLine="true"
    android:textSize="18sp"
    android:labelFor="@+id/data" />

</RelativeLayout>
...