2015-08-31 1 views
1

У меня есть сетка, которая показывает список изображений, и я применил прослушиватель режима выбора для этого gridview. Проблема заключается в том, когда я нажимаю длинный щелчок, чтобы выбрать набор изображений, они не подсвечиваются ..выделите изображение в режиме gridview, когда нажимаете длинное нажатие.

item_photo.xml

<?xml version="1.0" encoding="utf-8"?> 
<ImageView 
    android:id="@+id/photo" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:adjustViewBounds="true" 
    android:contentDescription="@string/media_thumbnail"/> 

fragment_photos.xml

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

    <!-- Empty View --> 
    <RelativeLayout 
     android:id="@+id/empty_view" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:visibility="gone"> 

     <ImageView 
      android:id="@+id/download_arrow" 
      android:layout_width="90dp" 
      android:layout_height="90dp" 
      android:layout_centerInParent="true" 
      android:contentDescription="@string/downloads" 
      android:src="@drawable/ic_photo"/> 

     <TextView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_below="@id/download_arrow" 
      android:layout_centerInParent="true" 
      android:layout_marginLeft="32dp" 
      android:layout_marginRight="32dp" 
      android:gravity="center" 
      android:text="@string/no_media"/> 
    </RelativeLayout> 

    <!-- Photos List --> 
    <GridView 
     android:id="@+id/list" 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:gravity="center" 
     android:horizontalSpacing="10dp" 
     android:numColumns="3" 
     android:paddingBottom="5dp" 
     android:choiceMode="multipleChoiceModal" 
     android:paddingTop="5dp" 
     android:stretchMode="columnWidth" 
     android:verticalSpacing="10dp" 
     android:visibility="gone"/> 

</RelativeLayout> 

PhotosFragment.java

public class PhotosFragment extends Fragment 
{ 
    @Bind (R.id.list) 
    GridView mGridView; 

    private MediaGridAdapter mAdapter; 
    private ArrayList<File> mFiles; 


    @Nullable 
    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) 
    { 
     View view = inflater.inflate(R.layout.fragment_media, container, false); 
     ButterKnife.bind(this, view); 

     mGridView.setMultiChoiceModeListener(new MultiChoiceModeListener()); 

     // set adapter and fetch files code .... 

     return view; 
    } 
} 

ответ

0

Нет эффекта магической подсветки, вы должны реализовать его сами, например, установка af который является полупрозрачным серым.

+0

Я попытался добавить listSelector и многие решения, но ни один из них не работал –

+0

добавьте эту неудачную попытку в ваше сообщение как отредактировать, вы вырезали слишком много информации, это не помогло бы –

Смежные вопросы