在我的 android 应用程序中,我正在使用Listview
每行 listview 将有 textview 和播放/暂停按钮。在这里,我在每个列表行中显示音频文件。当用户单击播放按钮时,音频文件将开始播放,播放按钮的图标将更改为暂停。如果我再次单击相同的按钮,它将停止该音频文件和暂停图标按钮将播放。
问题是,如果我正在访问第一行的播放按钮并单击另一行的播放按钮,那么第一行的图标应该会改变。我不知道如何实现此功能。请帮我解决这个问题。
customAdapter 的 getView() 方法:
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
RowItem_ringtone rowItem = getItem(position);
LayoutInflater mInflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.ringtone_row, null);
holder = new ViewHolder();
holder.txtTitle = (TextView) convertView
.findViewById(R.id.ringtoneTitle);
holder.btnPlay = (ImageButton) convertView
.findViewById(R.id.btnPlay);
holder.btnSet = (ImageButton) convertView.findViewById(R.id.btnSet);
convertView.setTag(holder);
} else
holder = (ViewHolder) convertView.getTag();
holder.txtTitle.setText(rowItem.getRingTitle());
holder.btnPlay.setTag(rowItem.getRingId());
holder.btnSet.setTag(rowItem.getRingId());
holder.btnPlay.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getContext(), v.getTag().toString(),
Toast.LENGTH_LONG).show();
if (CustomListViewAdapter_ringtone.mp != null) {
if (CustomListViewAdapter_ringtone.mp.isPlaying()) {
CustomListViewAdapter_ringtone.mp.stop();
CustomListViewAdapter_ringtone.mp.release();
}
}
mp = MediaPlayer.create(getContext(),
Integer.parseInt(v.getTag().toString()));
mp.start();
v.setBackgroundResource(R.drawable.set_icon);
btnId = Integer.parseInt(v.getTag().toString());
}
});
return convertView;
}