我使用 ArrayList 制作了一个歌曲列表,并且获得了所有信息,并且可以将其传递给第二个活动并在新页面上打开它。我想要的是当我单击歌曲列表时,它会在新页面中打开,新页面会显示歌曲的详细信息和图像。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView_Main=findViewById(R.id.listView_Main);
final Song song1 = new Song("Love Story","Taylor Swift","September 12,2008", "$1.29");
Song song2 = new Song("Lover","Taylor Swift","August 23,2019", "$1.29" );
Song song3 = new Song("I Forgot That You Existed", "Taylor Swift", "August 23,2019", "$1.29");
Song song4 = new Song("The Archer", "Taylor Swift", "August 23,2019", "$1.29");
Song song5 = new Song("I Think He Knows","Taylor Swift", "August 23,2019", "$1.29");
final List<Song> songs = new ArrayList<>();
songs.add(song1);
songs.add(song2);
songs.add(song3);
songs.add(song4);
songs.add(song5);
MainAdapter adapter = new MainAdapter(this, songs);
listView_Main.setAdapter(adapter);
listView_Main.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent=new Intent(view.getContext(),SongDetailActivity.class);
intent.putExtra("currentSong",(Serializable) songs.get(i));
startActivity(intent);
}
});
}
但我的问题是在第二个活动中,我不知道如何使用 setText 获取歌曲和图像的详细信息。因此,我在 String.xml 文件中制作了歌曲详细信息。我怎样才能在第二个活动中获得这些细节和图像?另外,我不知道如何获取第二个活动中歌曲列表的位置,我的意思是我单击的哪首歌曲的位置,并且它显示了我单击的那首歌曲的详细信息。
//这里是歌曲详细信息的第二个活动。//////
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_song_detail);
textViewSongDetail=findViewById(R.id.textView_SongDetail);
imageViewSongDetail=findViewById(R.id.image_SongDetail);
Song currentSong=(Song)getIntent().getSerializableExtra("currentSong");
}
回首忆惘然
相关分类