我设法从外部存储中读取歌曲的详细信息,并考虑添加一个排序按钮,因为它很混乱。但是,当我尝试按默认顺序对歌曲进行排序时,我基本上只对名称进行了排序,而歌曲曲目却没有随之排序。例如。歌曲1假设是Firefly-NCS,而歌曲2是Hero-Jam项目。但是,当我进行排序时,它会给我歌曲1作为Hero-Jam Project的“播放Firefly-NCS”配乐,并通过诗歌进行。
//Sort Button
Button button = findViewById(R.id.Sort);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
sortArrayList();
}
});
}
public void sortArrayList()
{
Arrays.sort(itemAll);
arrayAdapter.notifyDataSetChanged();
}
//The file where it read from my inner storage And display it
public ArrayList<File> ReadOnlyFile(File file)
{
ArrayList<File> arrayList = new ArrayList<>();
File[] allFiles = file.listFiles();
for (File indiviualFile : allFiles)
{
if (indiviualFile.isDirectory() && !indiviualFile.isHidden())
{
arrayList.addAll(ReadOnlyFile(indiviualFile));
}
else {
if (indiviualFile.getName().endsWith(".mp3"))
{
arrayList.add(indiviualFile);
}
}
}
return arrayList;
}
public void displayAudioSong()
{
final ArrayList<File> audioSongs = ReadOnlyFile(Environment.getExternalStorageDirectory());
itemAll = new String[audioSongs.size()];
for (int songCounter = 0; songCounter<audioSongs.size(); songCounter++)
{
itemAll[songCounter]=audioSongs.get(songCounter).getName();
}
arrayAdapter =new ArrayAdapter (this, android.R.layout.simple_list_item_1, itemAll );
mRecycle.setAdapter(arrayAdapter);
mRecycle.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
String songname = mRecycle.getItemAtPosition(position).toString();
startActivity(new Intent(getApplicationContext(), SongPlayer.class)
.putExtra("songs",audioSongs).putExtra("songname",songname)
.putExtra("pos",position));
}
});
}
我应该怎么做才能使我按排序按钮时对歌曲和曲目进行排序?