2
我正在開發一個應用程序,其中我想要一個mediabutton目前在可擴展標題`ie即將做播放/停止功能。 如何在播放歌曲時更改按鈕的背景以停止背景,並在播放歌曲時將其更改爲播放背景。 我也遇到了一個問題,當我想要一首歌曲應該停止並且它的背景改變時播放下一首可展開的列表視圖時出現。如何更改buttonClickClickClickClickClick在ExpandableListView中存在?
而且我的源代碼是:::
在可擴展的ListView我在我做過的事情
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
final String headerTitle = (String) getGroup(groupPosition);
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) this._context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.my_list_row, null);
}
TextView lblListHeader = (TextView) convertView
.findViewById(R.id.medicineName);
lblListHeader.setTypeface(null, Typeface.BOLD);
lblListHeader.setText(headerTitle);
final ImageView playpause = (ImageView) convertView
.findViewById(R.id.actionPlaypause);
playpause.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
///custom trick
v.setTag(orignalMedName);
mybtnListen.ListenToBtn(headerTitle, v);
}
});
if (groupPosition % 2 == 0) {
convertView.setBackgroundColor(Color.parseColor("#BBEBFF"));
} else {
convertView.setBackgroundColor(Color.parseColor("#ffffff"));
}
return convertView;
}
這是實現這種觀點
case R.id.actionPlaypause:
final ImageView actionPlPause = (ImageView) bt
.findViewById(R.id.actionPlaypause);
// previmg.add(actionPlPause);
Log.d("currentid", "" + actionPlPause.getId());
Uri myUri;
DatabaseHandler dbcheck = new DatabaseHandler(getActivity());
Log.d("mediacheck", "" + "media is playing");
// actionPlPause.setImageResource(R.drawable.stop);
boolean recordCheck = dbcheck.checkSinlgeEntry(
DatabaseHandler.TABLE_MEDICINERECORD, medicineName);
if (recordCheck) {
myUri = Uri.parse(Environment.getExternalStorageDirectory()
+ "/SaySong/USaRecord/" + medicineName
+ ".mp3"); // initialize Uri here
} else {
myUri = Uri.parse(Environment.getExternalStorageDirectory()
+ "/SaySong/USaRecord/"
+ medicineName + ".mp3"); // initialize Uri here
}
// mediaPlayer = new MediaPlayer();
if (!mediaPlayer.isPlaying()) {
// mediaPlayer.start();
actionPlPause.setImageResource(R.drawable.stop);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
try {
mediaPlayer.setDataSource(getActivity(), myUri);
mediaPlayer.prepare();
mediaPlayer.start();
SaveInRecentStore(medicineName);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer mp) {
Log.i("Completion Listener", "Song Complete");
Log.d("mediacheck", "" + "media playing finished");
actionPlPause.setImageResource(R.drawable.play);
mp.stop();
mp.reset();
// mp.release();
}
});
} else {
mediaPlayer.pause();
mediaPlayer.stop();
mediaPlayer.reset();
actionPlPause.setImageResource(R.drawable.play);
}
break;
巴迪它不是簡單得多...只是閱讀高亮顯示的影像?首先閱讀問題,然後回答..... !!不要浪費開發寶貴的時間... – DeepakPanwar