0

J'ai 6 fragments dans une disposition d'onglets coulissants. Tous ont RecyclerView mis en œuvre dans eux. J'ai peuplé le RecyclerView. Mais je l'un des fragments ne me permet pas de faire défiler, mais le reste fonctionne bien.Je ne peux pas faire défiler le recycleurVue d'un fragment

Voir le gif ci-dessous:

This is my problem

Genres.java

public class Genres extends Fragment { 


private static final String TAG = "Genres"; 
RecyclerView recyclerView_genre; 
GenresAdapter genresAdapter; 
ArrayList<GenresModel> Genrelist = new ArrayList<>(); 
long genreId; 
String genreName; 
Cursor genrecursor; 

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

    recyclerView_genre = view.findViewById(R.id.recyclerView_genre); 
    recyclerView_genre.setHasFixedSize(true); 
    LinearLayoutManager genreLayout = new LinearLayoutManager(getContext()); 
    recyclerView_genre.setLayoutManager(genreLayout); 




    String[] proj1 = {MediaStore.Audio.Genres.NAME, MediaStore.Audio.Genres._ID}; 


    genrecursor=getActivity().getContentResolver().query(MediaStore.Audio.Genres.EXTERNAL_CONTENT_URI,proj1,null, null, null); 

    if (genrecursor != null) { 
     if (genrecursor.moveToFirst()) { 
      do { 

       genreId = genrecursor.getLong(genrecursor.getColumnIndexOrThrow(MediaStore.Audio.Genres._ID)); 
       genreName = genrecursor.getString(genrecursor.getColumnIndexOrThrow(MediaStore.Audio.Genres.NAME)); 

       GenresModel genresModel = new GenresModel(genreId,genreName); 
       Genrelist.add(genresModel); 



       Collections.sort(Genrelist, new Comparator<GenresModel>() { 
        @Override 
        public int compare(GenresModel lhs, GenresModel rhs) { 
         return lhs.getGenreName().compareTo(rhs.getGenreName()); 
        } 
       }); 

      } while (genrecursor.moveToNext()); 
     } 

    } 
    genrecursor.close(); 





    genresAdapter = new GenresAdapter(getContext(),Genrelist); 
    recyclerView_genre.setAdapter(genresAdapter); 
    genresAdapter.notifyDataSetChanged(); 

    return view; 
} 

GenresAdapter.java

public class GenresAdapter extends RecyclerView.Adapter<GenresAdapter.GenresHolder> { 

Context gContext; 
ArrayList<GenresModel> GenreList = new ArrayList<>(); 

public GenresAdapter(Context gContext, ArrayList<GenresModel> genreList) { 
    this.gContext = gContext; 
    GenreList = genreList; 
} 

@Override 
public GenresAdapter.GenresHolder onCreateViewHolder(ViewGroup parent, int viewType) { 
    View view3 = LayoutInflater.from(gContext).inflate(R.layout.row_genre, parent, false); 
    return new GenresHolder(view3); 
} 

@Override 
public void onBindViewHolder(GenresAdapter.GenresHolder holder, int position) { 

    final GenresModel genresModel1 = GenreList.get(position); 

    holder.genreText.setText(genresModel1.getGenreName()); 

} 

@Override 
public int getItemCount() { 
    return GenreList.size(); 
} 

public class GenresHolder extends RecyclerView.ViewHolder { 

    TextView genreText; 

    public GenresHolder(View itemView) { 
     super(itemView); 

     genreText = itemView.findViewById(R.id.genreText); 
    } 
} 
} 

activity_genre.xml

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



<android.support.v7.widget.RecyclerView 
    android:id="@+id/recyclerView_genre" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingTop="130dp" 
    > 

</android.support.v7.widget.RecyclerView> 

</LinearLayout> 

row_genre.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_marginLeft="10dp" 
android:layout_marginStart="10dp" 
android:paddingTop="35dp" 
> 

<TextView 
    android:id="@+id/genreText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:textColor="#ffffff" 
    android:textSize="14sp" 
    /> 

</LinearLayout> 
+0

Quelle est la taille de 'GenreList'? –

+0

C'est dynamique. En fait, il montre les genres de chansons présentes sur la carte SD. – Rektirino

+0

D'accord, vous êtes sûr que la longueur de la liste est plus longue que l'écran? Peut-être une question stupide. –

Répondre