1
我使用自定义Adapter
在listView
中显示图像和文本。单击按钮时,我想用下一张图像替换图像。但是它只是在列表,而不是replacing.Below是我的代码片段:自定义列表视图不会取代视图
法在自定义视图从源码
public void BlockData() {
dataBase = dbHelper.getReadableDatabase();
Cursor mCursor = dataBase.rawQuery("SELECT * FROM "+ dbHelper.TABLE_NAME + " WHERE " + dbHelper.KEY_HNUM+ "=" + id, null);
if (mCursor.moveToFirst()) {
do {
category_Id.add(mCursor.getString(mCursor.getColumnIndex(dbHelper.KEY_HNUMM)));
} while (mCursor.moveToNext());
lv.setAdapter(new BlockAdapter(getApplicationContext(),category_Id,prgmImages));
stopManagingCursor(mCursor);
mCursor.close();
}
}
设置抓取图像
public View getView(final int pos, View child, final ViewGroup parent) {
final Holder mHolder;
LayoutInflater layoutInflater;
if (child == null) {
layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
child = layoutInflater.inflate(R.layout.secondlist, null);
mHolder = new Holder();
mHolder.txt_id = (TextView) child.findViewById(R.id.testingg);
mHolder.tx_img = (ImageView) child.findViewById(R.id.sac_img);
mHolder.butnxt = (Button) child.findViewById(R.id.button2);
mHolder.butpre = (Button) child.findViewById(R.id.button1);
child.setTag(mHolder);
} else {
mHolder = (Holder) child.getTag();
}
mHolder.txt_id.setText(category_Id.get(pos));
if (pos == 0) {
imgs = getResources().obtainTypedArray(R.array.sac_imgs);
mHolder.tx_img.setImageResource(imgs.getResourceId(id - 1, -1));
imgs.recycle();
}else{
imgs = getResources().obtainTypedArray(R.array.sac_imgs);
mHolder.tx_img.setImageResource(imgs.getResourceId(pos - 1, -1));
imgs.recycle();
}
mHolder.butnxt.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
id++;
BlockData();
}
});
return child;
}
protected ViewGroup findViewById(int txtViewPop) {
return null;
}
public class Holder {
TextView txt_id;
Button butnxt;
Button butpre;
TextView txt_fDate;
ImageView tx_img;
}
}
我应该怎么做每次按钮被点击时更换看法?我希望有人能指导我在正确的direction.thanks提前