Unable to select list item in HorizontalScrollView

I notice that by adding HorizontalScrollView, he disabled my ability to select items on mine ListView. This seems like a pretty basic / general function that needs to be added (I want to be able to move my element to the left to suggest a delete option), but HorizontalScrollViewit turns out to be incompatible with the elements that you would also like to touch Select. Please note that if I change HorizontalScrollViewto LinearLayoutor otherwise, the elements become available.

I suspected it touch listenersmight be ineffective because the ability to scan overridesany other touch, but I can’t really think about why this is not working. Can anyone help solve this problem? I would like to be able to use HorizontalScrollViewnext to click compatibility(if there is no other way to achieve the same functionality).

<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView
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:scrollbars="none">


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

        <android.support.constraint.ConstraintLayout
            android:id="@+id/constraintLayout4"
            android:layout_width="384dp"
            android:layout_height="110dp"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent">

            <TextView
                android:id="@+id/task_view_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="17dp"
                android:layout_marginTop="28dp"
                android:fontFamily="@font/robotolight"
                android:text="@string/task_name"
                android:textColor="@android:color/black"
                android:textSize="24sp"
                app:layout_constraintStart_toEndOf="@+id/task_view_icon"
                app:layout_constraintTop_toTopOf="parent" />

            <ImageView
                android:id="@+id/task_view_icon"
                android:layout_width="77dp"
                android:layout_height="77dp"
                android:layout_marginStart="17dp"
                android:layout_marginTop="17dp"
                android:contentDescription="@+string/icon"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/main_page_icon_switch_x4" />

            <TextView
                android:id="@+id/task_view_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="50dp"
                android:layout_marginTop="36dp"
                android:fontFamily="@font/robotolight"
                android:text="@string/duration"
                android:textColor="@android:color/black"
                android:textSize="14sp"
                app:layout_constraintStart_toEndOf="@+id/task_view_name"
                app:layout_constraintTop_toTopOf="parent" />

            <TextView
                android:id="@+id/task_view_detail"
                android:layout_width="228dp"
                android:layout_height="31dp"
                android:layout_marginStart="17dp"
                android:fontFamily="@font/robotolight"
                android:text="@string/task_view_detail_literal"
                android:textColor="@android:color/black"
                android:textSize="12sp"
                app:layout_constraintStart_toEndOf="@+id/task_view_icon"
                app:layout_constraintTop_toBottomOf="@+id/task_view_name" />



        </android.support.constraint.ConstraintLayout>
        <android.support.constraint.ConstraintLayout
            android:id="@+id/task_delete"
            android:layout_width="116dp"
            android:layout_height="110dp"
            android:background="@color/colorPrimary"
            app:layout_constraintEnd_toEndOf="@id/constraintLayout4"
            app:layout_constraintTop_toTopOf="parent">

            <TextView
                android:id="@+id/task_delete_literal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginEnd="13dp"
                android:layout_marginTop="39dp"
                android:fontFamily="@font/roboto_regular"
                android:text="@string/delete"
                android:textColor="@android:color/background_light"
                android:textSize="24sp"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintTop_toTopOf="parent" />
        </android.support.constraint.ConstraintLayout>
    </LinearLayout>
</HorizontalScrollView>
+4
source share
1 answer

, , . , ListView - HorizontalScrollView XML, ListView ( ListView ), , onClickListener.

:

ConstraintLayout myLayout = convertView.findViewById(R.id.constraintLayout1);
    ConstraintLayout anotherLayout = convertView.findViewById(R.id.constraintLayout2); //lets' say I'm using this to delete the item when clicked



    myLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent exampleIntent = new Intent(viewParent.getContext(), SomeActivity.class); 
        }
    });
    anotherLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(view.getContext());

            builder.setMessage("Are You Sure?").setNegativeButton("No", null);
            builder.setPositiveButton("yes", new android.support.v7.app.AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    Database database = new Database(viewParent.getContext());
                    database.deleteItem(item);

                    List<Item> items = database.getItems();
                    ListView list = (ListView) viewParent.findViewById(R.id.my_linear_list);

                    //List<Item> items = new Database(viewParent.getContext()).getItems();

                    TaskAdapter adapterNew = new ItemAdapter(viewParent.getContext(), tasks);

                    list.setAdapter(adapterNew);
                }
            });
            builder.show();
        }
    });
0

Source: https://habr.com/ru/post/1691080/


All Articles