Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java holder.position=位置; } @凌驾 public int getItemCount(){ 返回listOfUsableApis.size(); } @凌驾 公共长getItemId(int位置){ 返回长。值(位置); } 公共类设置ViewHolder扩展了RecyclerView.ViewHolder{ 公共职位; 公共文本视图文本视图; 公共设置ViewHolder(文本视图v){ 超级(五); textView=v; } } } 私有类设置DetailsLookup扩展ItemDetailsLookup{ @可空 @凌驾 public ItemDetails getItemDetails(@NonNull MotionEvent事件){ View-View=settingsRecyclerView.findChildViewUnder(event.getX(),event.getY()); 如果(视图!=null){ final RecyclerView.ViewHolder ViewHolder=设置RecyclerView.getChildViewHolder(视图); if(设置的视图持有者实例适配器。设置视图持有者){ 最终设置Adapter.SettingViewHolder SettingViewHolder=(SettingsAdapter.SettingViewHolder)viewHolder; 返回新的ItemDetailsLookup.ItemDetails(){ @凌驾 public int getPosition(){ 返回viewHolder.getAdapterPosition(); } @可空 @凌驾 公共长getSelectionKey(){ 返回Long.valueOf(设置ViewHolder.position); } }; } } 返回null; } } }_Java_Android_Kotlin - Fatal编程技术网

Java holder.position=位置; } @凌驾 public int getItemCount(){ 返回listOfUsableApis.size(); } @凌驾 公共长getItemId(int位置){ 返回长。值(位置); } 公共类设置ViewHolder扩展了RecyclerView.ViewHolder{ 公共职位; 公共文本视图文本视图; 公共设置ViewHolder(文本视图v){ 超级(五); textView=v; } } } 私有类设置DetailsLookup扩展ItemDetailsLookup{ @可空 @凌驾 public ItemDetails getItemDetails(@NonNull MotionEvent事件){ View-View=settingsRecyclerView.findChildViewUnder(event.getX(),event.getY()); 如果(视图!=null){ final RecyclerView.ViewHolder ViewHolder=设置RecyclerView.getChildViewHolder(视图); if(设置的视图持有者实例适配器。设置视图持有者){ 最终设置Adapter.SettingViewHolder SettingViewHolder=(SettingsAdapter.SettingViewHolder)viewHolder; 返回新的ItemDetailsLookup.ItemDetails(){ @凌驾 public int getPosition(){ 返回viewHolder.getAdapterPosition(); } @可空 @凌驾 公共长getSelectionKey(){ 返回Long.valueOf(设置ViewHolder.position); } }; } } 返回null; } } }

Java holder.position=位置; } @凌驾 public int getItemCount(){ 返回listOfUsableApis.size(); } @凌驾 公共长getItemId(int位置){ 返回长。值(位置); } 公共类设置ViewHolder扩展了RecyclerView.ViewHolder{ 公共职位; 公共文本视图文本视图; 公共设置ViewHolder(文本视图v){ 超级(五); textView=v; } } } 私有类设置DetailsLookup扩展ItemDetailsLookup{ @可空 @凌驾 public ItemDetails getItemDetails(@NonNull MotionEvent事件){ View-View=settingsRecyclerView.findChildViewUnder(event.getX(),event.getY()); 如果(视图!=null){ final RecyclerView.ViewHolder ViewHolder=设置RecyclerView.getChildViewHolder(视图); if(设置的视图持有者实例适配器。设置视图持有者){ 最终设置Adapter.SettingViewHolder SettingViewHolder=(SettingsAdapter.SettingViewHolder)viewHolder; 返回新的ItemDetailsLookup.ItemDetails(){ @凌驾 public int getPosition(){ 返回viewHolder.getAdapterPosition(); } @可空 @凌驾 公共长getSelectionKey(){ 返回Long.valueOf(设置ViewHolder.position); } }; } } 返回null; } } },java,android,kotlin,Java,Android,Kotlin,布局 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="fill_parent" android:layout_height="fill_parent" android:baselineAligned="false"

布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="false"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#454545"
        android:weightSum="100">

        <Button
            android:id="@+id/settings_back_button"
            android:background="#454545"
            android:drawableStart="@drawable/arrow_white"
            android:drawableLeft="@drawable/arrow_white"
            android:layout_gravity="start"
            android:layout_width="@dimen/ll_mdu_10"
            android:layout_height="@dimen/ll_mdu_10"
            android:layout_weight="5"/>

        <Space
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="90"
            />

        <Button
            android:id="@+id/settings_apply_button"
            android:background="#454545"
            android:drawableStart="@android:drawable/ic_menu_save"
            android:drawableLeft="@android:drawable/ic_menu_save"
            android:layout_gravity="end"
            android:layout_width="@dimen/ll_mdu_10"
            android:layout_height="@dimen/ll_mdu_10"
            android:layout_weight="5"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingLeft="@dimen/activity_horizontal_margin"
        android:paddingTop="@dimen/activity_vertical_margin"
        android:paddingRight="@dimen/activity_horizontal_margin"
        android:paddingBottom="@dimen/activity_vertical_margin">

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Long-press for first setting, then tap other settings for multiple selection"
            app:layout_constraintBottom_toTopOf="@+id/settingsRecyclerView"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/settingsRecyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scrollbars="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView" />

    </LinearLayout>

</LinearLayout>

这个文档很难阅读。它需要一个例子

  • 难以理解的Kotlin示例

  • Google IO介绍此功能(但在Kotlin中)

  • 另一个Java示例


  • 您应该试试这个:谢谢@ArjunVyas在本例中,我主要是问如何具体实现SelectionTracker,而不是启用列表项选择的其他方法。
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:baselineAligned="false"
        android:orientation="vertical">
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#454545"
            android:weightSum="100">
    
            <Button
                android:id="@+id/settings_back_button"
                android:background="#454545"
                android:drawableStart="@drawable/arrow_white"
                android:drawableLeft="@drawable/arrow_white"
                android:layout_gravity="start"
                android:layout_width="@dimen/ll_mdu_10"
                android:layout_height="@dimen/ll_mdu_10"
                android:layout_weight="5"/>
    
            <Space
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="90"
                />
    
            <Button
                android:id="@+id/settings_apply_button"
                android:background="#454545"
                android:drawableStart="@android:drawable/ic_menu_save"
                android:drawableLeft="@android:drawable/ic_menu_save"
                android:layout_gravity="end"
                android:layout_width="@dimen/ll_mdu_10"
                android:layout_height="@dimen/ll_mdu_10"
                android:layout_weight="5"/>
    
        </LinearLayout>
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingBottom="@dimen/activity_vertical_margin">
    
            <TextView
                android:id="@+id/textView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Long-press for first setting, then tap other settings for multiple selection"
                app:layout_constraintBottom_toTopOf="@+id/settingsRecyclerView"
                app:layout_constraintTop_toTopOf="parent" />
    
            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/settingsRecyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scrollbars="vertical"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/textView" />
    
        </LinearLayout>
    
    </LinearLayout>
    
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/setting_list_item_text_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/setting_background"
        android:gravity="center_vertical"
        android:minHeight="?android:attr/listPreferredItemHeightSmall"
        android:paddingStart="?android:attr/listPreferredItemPaddingStart"
        android:paddingEnd="?android:attr/listPreferredItemPaddingEnd"
        android:textAppearance="?android:attr/textAppearanceListItemSmall" />
    
    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:drawable="@android:color/holo_green_dark" android:state_activated="true" />
        <item android:drawable="@android:color/white" />
    </selector>