4
我有一個列表視圖,其中有圖像,標題,選項和播放/暫停按鈕。當我單擊一行中的播放按鈕,然後單擊另一行中的播放按鈕時,兩個按鈕的背景都保持暫停。所以我希望當我點擊連續的播放按鈕,然後點擊另一行的播放按鈕時,第一個按鈕的背景應該變爲播放,而第二個的背景應該保持暫停。在此先感謝更新播放,暫停按鈕在列表視圖
下面是代碼
公共類MyAdapter延伸BaseAdapter {
int itemnum;
Boolean playing = false;
Context context;
int layoutResourceId;
// RingTone data[] = null;
private LayoutInflater mInflater;
String[] Title;
int[] Img;
ListView listview;
public MyAdapter(Context context, int layoutResourceId, String[] Title,int[] Img, int[] Tone, ListView listview) {
mInflater = LayoutInflater.from(context);
this.layoutResourceId = layoutResourceId;
this.context = context;
this.Title=Title;
this.Img=Img;
ListActivity.Tone=Tone;
this.listview=listview;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = convertView;
RingToneHolder holder = null;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listrow, null);
}
holder = new RingToneHolder();
// RingTone aa = data[position];
holder.imgIcon = (ImageView)convertView.findViewById(R.id.list_image);
holder.txtTitle = (TextView)convertView.findViewById(R.id.title);
holder.playbtn = (Button)convertView.findViewById(R.id.playbtn);
holder.btn_alert_dialog = (Button)convertView.findViewById(R.id.alert_dialog_btn);
holder.pausebtn = (Button)convertView.findViewById(R.id.pausebtn);
holder.txtTitle.setText(Title[position]);
// holder.txtTitle.setText(aa.title);
holder.imgIcon.setImageResource(Img[position]);
//holder.playbtn.setInputType(aa.btn);S
holder.playbtn.setTag(position);
holder.btn_alert_dialog.setTag(position);
holder.playbtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(mp == null){
listview.invalidateViews();
mp = MediaPlayer.create(context,Tone[Integer.parseInt(arg0.getTag().toString())]);
mp.start();
playing = true;
itemnum = Integer.parseInt(arg0.getTag().toString());
//Toast.makeText(context, "ist playing", Toast.LENGTH_LONG).show();
arg0.setBackgroundResource(R.drawable.pause);
}
else {
if(mp.isPlaying() && itemnum == Integer.parseInt(arg0.getTag().toString())){
listview.invalidateViews();
mp.pause();
playing = false;
//Toast.makeText(context, " paused", Toast.LENGTH_LONG).show();
arg0.setBackgroundResource(R.drawable.play_btn);
}
else{
if(playing == false && itemnum == Integer.parseInt(arg0.getTag().toString())){
listview.invalidateViews();
mp.start();
playing = true;
arg0.setBackgroundResource(R.drawable.pause);
}
else {
//.invalidate();
listview.invalidateViews();
mp.stop();
mp.release();
mp = MediaPlayer.create(context,Tone[Integer.parseInt(arg0.getTag().toString())]);
mp.start();
playing = true;
itemnum = Integer.parseInt(arg0.getTag().toString());
//Toast.makeText(context, "playing", Toast.LENGTH_LONG).show();
arg0.setBackgroundResource(R.drawable.pause);
}
}
}
}
});
你能幫助我嗎?我怎麼能在這種情況下得到指針/索引。 –