我的应用程序在列表的一行中生成一个列表视图(即音频列表),其中包含 2 个按钮和 3 个文本视图。这两个按钮通过使用实现基本适配器的适配器变得可点击。其中一个按钮用于意图视图另一个播放音频。单击播放按钮时,我更改了按钮的背景(播放)。但问题是多个播放按钮的背景已更改,如位置 0、10、20、31、41 ......当我单击 0 该行,我还想知道如何更改所选列表视图的背景以区分正在播放的音频与其他音频...
请..向我建议解决方案..提前感谢以下我的适配器类
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
convertView = l_Inflater.inflate(R.layout.lv_layout1, null);
holder = new ViewHolder();
holder.Title = (TextView) convertView.findViewById(R.id.Title);
holder.Date = (TextView) convertView.findViewById(R.id.Date);
holder.Time = (TextView) convertView.findViewById(R.id.Time);
holder.Duration = (TextView) convertView.findViewById(R.id.Duration1);
holder.view = (Button) convertView.findViewById(R.id.View);
holder.play = (Button) convertView.findViewById(R.id.Play);
holder.r_layout = (RelativeLayout) convertView.findViewById(R.id.r_layout);
holder.Duration.setVisibility(View.INVISIBLE);
holder.play.setBackgroundResource(0x7f020009);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.play.setOnClickListener(new View.OnClickListener()
{
public void onClick(View convertView) throws IllegalStateException
{
// TODO Auto-generated method stub
//here is code for play/stop the audio
holder.play.setBackgroundResource(0x7f020009);
}
});
holder.view.setOnClickListener(new View.OnClickListener() {
public void onClick(View convertView) {
// TODO Auto-generated method stub
Log.i("View","hai");
Intent i=new Intent(context,audio_player.class);
Bundle bd=new Bundle();
String sel=itemDetailsrrayList.get(position).getTitle();
String dur=itemDetailsrrayList.get(position).getDuration();
bd.putString("audioID",sel);
bd.putString("totalDuration",dur);
i.putExtras(bd);
System.out.println("After intent called");
context.startActivity(i);
((Activity) context).finish();
}
});
return convertView;
}
static class ViewHolder {
TextView Title,Date,Time,Duration;
ListView lv;
Button view,play;
RelativeLayout r_layout;
}
}