2017-12-20 5 views
4

HorizontalScrollViewを追加すると、ListViewのアイテムを選択する機能が無効になっています。これは非常に基本的な/よくある機能のようです(削除オプションを提供するためにアイテムを左にスワイプしたいと思っています)が、HorizontalScrollViewはタッチして選択したいアイテムと互換性がないようです。 HorizontalScrollViewLinearLayoutに変更すると、アイテムが選択可能になることに注意してください。Horizo​​ntalScrollViewのリストアイテムをクリックできません

touch listenersは、スワイプ能力が他の種類のタッチのために無効である可能性があると疑われていましたが、それ以外の理由で実際にはうまくいかないとは思えません。誰でもこの問題を解決するのに役立つことができますか?同じ機能を実現する別の方法がない限り、HorizontalScrollViewclick compatibilityと一緒に使用したいと考えています。

<?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> 
+0

RecyclerViewに対して水平リストビューを構築する方法を試してみてください? https://stackoverflow.com/questions/28460300/how-to-build-a-horizo​​ntal-listview-with-recyclerview – R2R

+0

私が誤解した場合は私を許しますが、垂直のListView行に水平スクロールさせたいのですが、水平リストビューではありません。 – MadThink

+0

スクリーンショットの例を共有できますか? – R2R

答えて

0

この問題を抱えている人にとっては、これを回避する方法を見つけることができました。私の問題は、XMLのHorizontalScrollViewの設定のためにListViewアイテムをクリックできないということでしたが、私の場合は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(); 
     } 
    }); 
関連する問題