In my android application, I am using Listviewand each row of listview will have textview and play/pause button. Here I am displaying audio file in each list row.When user click play button, audio file will start and the icon of play button will be changed to pause .If i click same button again, it will stop that audio file and icon of pause button will be to play.
The problem is that if i am accessing the play button of 1st row and i click on play button of another row, then icon of 1st row should change.I don't know how to achieve this functionality. Please help me to solve this problem.
getView() method of customAdapter :
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;
}