我正在尝试开发音乐播放器应用。
首先,我从listview中选择一首音乐。然后音乐播放屏幕打开选定的音乐。同时出现通知。无论您身在何处,如果单击通知,音乐播放器屏幕将打开当前音乐。然后,如果需要,可以按返回按钮进入音乐列表。
在API 19上;在通知音乐播放屏幕并按下后退按钮后,会显示音乐列表,但不会点击项目。但更高的API没有问题。
唯一的麻烦;来自API 19的通知小组。
我无法理解这个问题。音乐列表onCreate方法如下。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.showmusicfiles);
filesFound=(ListView)findViewById(R.id.files_found);
items = new ArrayList<FileItem>();
context = getApplicationContext();
String path = Environment.getExternalStorageDirectory() +
File.separator + "MusicApp"+File.separator+"mp3";
File f = new File(path);
final File fileList[] = f.listFiles();
for (File file : f.listFiles()) {
FileItem item=new FileItem();
item.setDescription(file.getName());
item.setFullPath(file.getAbsolutePath());
items.add(item);
}
searchResults=sortByDate(items);
adapter = new ArrayAdapter<FileItem>(getApplicationContext(), R.layout.music_file_item, searchResults){
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
if(convertView == null){
convertView = getLayoutInflater().inflate(R.layout.music_file_item, parent, false);
}
TextView description = (TextView)convertView.findViewById(R.id.file_description);
final FileItem searchResult = searchResults.get(position);
description.setText(searchResult.getDescription().replace(".mp3",""));
convertView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
deleteFileFromList(searchResults.get(position).getFullPath(),position);
break;
case DialogInterface.BUTTON_NEGATIVE:
toast("yoh dedın");
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(ShowMusicFiles.this);
builder.setMessage("Are you sure you want to delete").setPositiveButton("Yes", dialogClickListener)
.setNegativeButton("No", dialogClickListener).show();
return true;
}
});
convertView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
FileTypeList = new ArrayList<File>();
FileTypeList = FileItemToFile(searchResults);
DescriptionList= new ArrayList<String>();
DescriptionList = getDescriptionList(searchResults);
playerIntent = new Intent(context, MusicPlayer.class);
playerIntent.putExtra("songPosition",position);
playerIntent.putExtra("songList",FileTypeList);
playerIntent.putExtra("descriptionList",DescriptionList);
playerIntent.putExtra("fromWhere","musicList");
playerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(playerIntent);
}
});
return convertView;
}
};
filesFound.setAdapter(adapter);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
final ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view_music);
navigationView.setNavigationItemSelectedListener(this);
}
我在音乐播放屏幕上的背压方法仅包括转到音乐列表页面的意图。所以我不认为我需要写入音乐播放代码。
感谢。
@Override
public void onBackPressed() {
Intent goToMusicList = new Intent(MusicPlayer.this,ShowMusicFiles.class);
startActivity(goToMusicList);
}
答案 0 :(得分:0)
在filesFOund.invalidate()
之前致电filesFound.setAdapter(adapter)
。如果这不能解决问题,那么尝试将ShowMusicFiles活动的launchMode设置为singleTop。