我正在嘗試開發音樂播放器應用程序。列表視圖項不在API 19上單擊,但單擊上API的
首先,我從listview中選擇音樂。然後音樂播放屏幕隨着選定的音樂打開。同時出現通知。無論您身處何處,如果您點擊通知,音樂播放器屏幕將以當前音樂打開。然後,如果你願意,你可以按回來按鈕去音樂列表。
關於API 19's;在通知音樂播放畫面並按下後退按鈕後,會顯示音樂列表,但不會點擊項目。但更高的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);
}
您是否在R.layout.music_file_item中嘗試過使用android:clickable =「true」?或convertView.setClickable(true)? – geecko
在佈局文件上,可點擊的已添加。我也嘗試過形式的java代碼,但它沒有工作。 – Arif