と一緒に並んbutton
でいます。同じ行のボタンをクリックしながらテキストビューの値を増やしたい。以下は私のコードです。ここでは、必要に応じて単一の行ではなく複数の行を更新しています。textview
listview
package com.example.digitalmenuactivity;
public class ListAdapter extends BaseAdapter {
private Activity activity;
private Activity activity1;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader;
private int mCounter1=1;
private int counter=1;
private int[] counters;
int pos;
public ListAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
activity = a;
data=d;
inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
imageLoader=new ImageLoader(activity.getApplicationContext());
counters = new int[5];
}
static class ViewHolder {
protected TextView mSwitcher1=null;
protected Button btnDelete=null;
protected TextView title=null;
protected TextView artist=null;
protected TextView duration=null;
protected ImageView thumb_image=null;
}
public int getCount() {
return data.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
@Override
public int getItemViewType(int position) {
// TODO Auto-generated method stub
return position;
}
public View getView(final int position,final View convertView, ViewGroup parent) {
View vi=convertView;
final ViewHolder viewHolder;
pos = getItemViewType(position);
if(convertView==null)
{
vi = inflater.inflate(R.layout.list_row, null);
viewHolder = new ViewHolder();
viewHolder.title = (TextView)vi.findViewById(R.id.title);
viewHolder.artist = (TextView)vi.findViewById(R.id.description);
viewHolder.duration = (TextView)vi.findViewById(R.id.price);
viewHolder.thumb_image =(ImageView)vi.findViewById(R.id.list_image);
viewHolder.btnDelete = (Button)vi.findViewById(R.id.plus);
viewHolder.mSwitcher1 = (TextView) vi.findViewById(R.id.switcher1);
vi.setTag(viewHolder);
}
else {
viewHolder = (ViewHolder) vi.getTag();
}
viewHolder.btnDelete.setTag(pos);
viewHolder.mSwitcher1.setTag(pos);
viewHolder.btnDelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
pos = (Integer) view.getTag();
int temp=counters[pos];
temp++;
counters[pos]= temp;
viewHolder.mSwitcher1.setText(String.valueOf(counters[pos]));
notifyDataSetChanged();
Log.d("^^^^^^", "button clicked" + counters.length);
Log.d("^^^^^^", "temp" + temp);
}
});
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(position);
viewHolder.title.setText(song.get(FoodActivity.KEY_TITLE));
viewHolder.artist.setText(song.get(FoodActivity.KEY_ARTIST));
viewHolder.duration.setText(song.get(FoodActivity.KEY_DURATION));
imageLoader.DisplayImage(song.get(FoodActivity.KEY_THUMB_URL),viewHolder.thumb_image);
return vi;
}
}