imagepaths
sqlite からdata( ) を取得するので、以前simplecursoradapter
はgridview
. 以下のコードに示すように、各グリッドビュー項目にはイメージビューとチェックボックスが含まれています。ここで私の最初の問題は、グリッドビューがスクロールされるたびに画像の位置が変更され、しばらくすると自分の場所に落ち着くように見えることです。これらの問題は、スクロール時にビューが再利用されるために発生していると思います。
2 番目の問題は、いくつかcheckboxes
チェックしてスクロールすると、チェックボックスの値が変更さcheckboxes
れることです。誰かがこの問題を回避するために私を助けてくれますか?
public class ImagesScreen extends Activity{
public void onCreate(Bundle savedInstanceState){
.......................
.......................
gridView.setAdapter(imagecursorAdapter);
}
}
アダプタ クラス:
public class ImageCursorAdapter extends SimpleCursorAdapter{
private int layout;
private LayoutInflater mLayoutInflater;
private Context mContext;
ViewHolder vh;
public ImageAdapter(Context context, int layout, Cursor c,String[] from, int[] to) {
super(context, layout, c, from, to,0);
this.layout = layout;
mLayoutInflater=LayoutInflater.from(context);
mContext = context;
}
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v = mLayoutInflater.inflate(layout, parent, false);
return v;
}
public void bindView(final View v, final Context context, Cursor c) {
final int id = c.getInt(c.getColumnIndex("id"));
final String imagepath = c.getString(c.getColumnIndex("paths"));
vh = new ViewHolder();
vh.imageview = (ImageView)v.findViewById(R.id.imageView1);
vh.checkBox = (CheckBox)v.findViewById(R.id.checkBox1);
vh.checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){
Log.d("ischecked",""+isChecked);
}
});
File imgFile = new File(imagepath);
if(imgFile.exists()){
Bitmap imageBitmap = decodeFile(imgFile);
vh.imageview.setImageBitmap(imageBitmap);
}
}
static class ViewHolder{
public ViewHolder(){}
public ImageView imageview;
public CheckBox checkBox;
}
}