음악 앱을 만들고 있는데 앨범 표지를 표시하는 "앨범"조각이 있습니다 (RecyclerView
). 내가 원하는 것은 이러한 항목 (앨범 표지) 중 하나를 클릭하면 특정 앨범의 노래가 포함 된 다른 활동 (albumsDetails.java)으로 이동해야합니다. 그리고이 노래들은 모두 RecyclerView
에 표시되어야합니다. 의도를 사용하는 방법을 알고 많은 일을 시도했지만 그 중 아무 것도 작동하지 않습니다.recyclerView의 항목을 클릭하고 클릭 한 항목의 세부 정보가 포함 된 다른 recyclerView로 이동하는 방법?
안드로이드 스튜디오에 대한 새로운 질문이므로 제발 저의 질문을 잊지 마십시오.
당신이
View.setOnClickListener()를 CLL 수 ViewHolder 클래스에서 Album.java
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.albums_activity, container, false);
recyclerViewAlbum = view.findViewById(R.id.albums_reyclerView);
recyclerViewAlbum.setHasFixedSize(true);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(),2);
recyclerViewAlbum.setLayoutManager(gridLayoutManager);
albumsAdapter = new AlbumsAdapter(SongList1,getContext(), new AlbumsAdapter.RecyclerItemClickListener() {
@Override
public void onClickListener(SongInfoModel song, int position) {
Intent i = new Intent(getContext(), AlbumDetails.class);
i.putExtra("SongName", song.getSongName());
startActivity(i);
Activity activity = getActivity();
if (activity instanceof MainActivity) {}
}
});
Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
Cursor cursor = getActivity().getContentResolver().query(uri, null, selection, null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
String name = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.TITLE));
String artist = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ARTIST));
long duration = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.DURATION));
String album = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM));
String data = cursor.getString(cursor.getColumnIndex(MediaStore.Audio.Media.DATA));
long albumId = cursor.getLong(cursor.getColumnIndex(MediaStore.Audio.Media.ALBUM_ID));
Uri sArtworkUri = Uri.parse("content://media/external/audio/albumart");
Uri albumArtUri = ContentUris.withAppendedId(sArtworkUri, albumId);
SongInfoModel s = new SongInfoModel(name, artist, null, album, null, duration, data,albumArtUri);
SongList1.add(s);
} while (cursor.moveToNext());
}
cursor.close();
Collections.sort(SongList1, new Comparator<SongInfoModel>() {
@Override
public int compare(SongInfoModel lhs, SongInfoModel rhs) {
return lhs.getAlbum().compareTo(rhs.getAlbum());
}
});
}
recyclerViewAlbum.setAdapter(albumsAdapter);
albumsAdapter.notifyDataSetChanged();
return view;
}
}
AlbumsDetails.java
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.album_details);
albumsDetails_reyclerView = findViewById(R.id.albumsDetails_reyclerView);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext());
albumsDetails_reyclerView.setLayoutManager(linearLayoutManager);
Bundle extras = getIntent().getExtras();
if(extras != null){
}
albumsDetailsAdapter = new AlbumsDetailsAdapter(getApplicationContext(), SongList2, new AlbumsDetailsAdapter.RecyclerItemClickListenerAlbumsDetails() {
@Override
public void onClickListener(SongInfoModel songInfoModelAlbumDetails, int positionAlbumDetails) {
}
}){
};
albumsDetails_reyclerView.setAdapter(albumsDetailsAdapter);
albumsDetailsAdapter.notifyDataSetChanged();
}
}
어댑터 내부의보기 홀더 클래스를 클릭하십시오. 그것은 어댑터에서 클릭을 취하는 적절한 방법입니다. –