我使用自定义ListView
开发了一个Android应用程序。我的自定义ListView
由Textview
,ImageView
和2 ImageButton
组成。我想点击它时更改ImageButton
的资源。 (例如:从游戏到停止)。更清楚的是,我在下面附上我的设计。
如何从ImageButton
控制我的Activity
?
public class MyCustomBaseAdapterSurat extends BaseAdapter {
private static ArrayList<SearchResults> searchArrayList;
private LayoutInflater mInflater;
ViewHolder holder;
private StreamingMediaPlayer audioStreamer;
public MyCustomBaseAdapterSurat(Context context,
ArrayList<SearchResults> results) {
searchArrayList = results;
mInflater = LayoutInflater.from(context);
}
@Override
public int getCount() {
return searchArrayList.size();
}
@Override
public Object getItem(int position) {
return searchArrayList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.customlistsurat, null);
holder = new ViewHolder();
holder.txtName = (TextView) convertView.findViewById(R.id.name);
holder.iv = (ImageView) convertView.findViewById(R.id.imageView1);
holder.play = (ImageButton) convertView
.findViewById(R.id.imageButton1);
holder.rep = (ImageButton) convertView
.findViewById(R.id.imageButton2);
holder.play.setOnClickListener(klikplay);
// holder.rep.setOnClickListener(klikrep);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.rep.setId(searchArrayList.get(position).getIdRep());
holder.play.setId(searchArrayList.get(position).getIdPlay());
holder.txtName.setText(searchArrayList.get(position).getName());
holder.iv.setBackgroundResource(searchArrayList.get(position)
.getDrawable());
return convertView;
}
static class ViewHolder {
TextView txtName;
ImageView iv;
ImageButton play;
ImageButton rep;
}
private OnClickListener klikplay = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
holder.play.setBackgroundResource(searchArrayList.get(v.getId())
.getDrawable());
//startStreamingAudio();
}
};
}