У меня проблема с передачей идентификатора из базы данных SQLite на новую вторую страницу активности.Я думаю, что мой проходной идентификатор является нулевым.Но я не знаю, какую часть мне нужно исправить.И я думаю, что это также связано со String и ArrayList.Первое кодирование является основным видом деятельности.Второе кодирование - это второе действие (ImageList).Третья кодировка - CustomGridAdapter для первой страницы.четвертая кодировка - CustomGridAdapter1 для второй страницы.Любой может исправить мою кодировку.
gridView = (GridView) findViewById(R.id.gridView1);
imageList = new ArrayList<>();
adapter = new CustomGridAdapter(this, R.layout.image_item, imageList);
gridView.setAdapter(adapter);
// get all data from sqlite
Cursor cursor = databaseAccess.getData("SELECT * FROM IMAGE");
imageList.clear();
while (cursor.moveToNext()) {
String id = cursor.getString(0);
String name = cursor.getString(1);
byte[] image = cursor.getBlob(2);
imageList.add(new Things(id, name, image));
}
adapter.notifyDataSetChanged();
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View view, int position, long id) {
view.setSelected(true);
final Things labels=imageList.get(position);
Intent passIntent = new Intent(MainActivity.this, ImageList.class);
passIntent.putExtra("keyid", String.valueOf(labels));
startActivity(passIntent);
}
});
gridView = (GridView) findViewById(R.id.gridView2);
imageList = new ArrayList<>();
adapter = new CustomGridAdapter1(this, R.layout.image_general);
gridView.setAdapter(adapter);
Bundle showData = getIntent().getExtras();
rowId = showData.getString("keyid");
databaseAccess = new DatabaseAccess(getApplicationContext());
cursor = databaseAccess.getImage(rowId);
if(cursor.moveToFirst()) {
do{
String id = cursor.getString(1);
String name = cursor.getString(2);
byte[] image = cursor.getBlob(3);
String imgid = cursor.getString(4);
General general =new General(id, name, image,imgid);
adapter.add(general);
} while(cursor.moveToNext());
}
adapter.notifyDataSetChanged();
}
public class CustomGridAdapter extends BaseAdapter {
private Context context;
private int layout;
// private ArrayList<Things> ImageList;
List ImageList= new ArrayList();
public CustomGridAdapter(Context aContext, int layout, List ImageList) {
this.context = aContext;
this.ImageList =ImageList;
this.layout=layout;
}
@Override
public int getCount() {
return ImageList.size();
}
@Override
public Object getItem(int position) {
return ImageList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
private class ViewHolder {
TextView Thing;
ImageView ThingImage;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
if (convertView == null) {
// convertView = layoutInflater.inflate(R.layout.gridgeneral, null);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.image_item, parent, false);
holder.ThingImage = (ImageView) convertView.findViewById(R.id.imageView_flag);
holder.Thing= (TextView) convertView.findViewById(R.id.thing);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
Things things= (Things) this.getItem(position);
holder.Thing.setText(things.getName());
byte[] thingName = things.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(thingName, 0, thingName.length);
holder.ThingImage.setImageBitmap(bitmap);
return convertView;
}
}
public class CustomGridAdapter1 extends BaseAdapter {
private Context context;
private int layout;
// private ArrayList<General> ImageList;
List ImageList= new ArrayList();
public CustomGridAdapter1(Context aContext, int layout) {
this.context = aContext;
this.ImageList = ImageList;
this.layout = layout;
}
@Override
public int getCount() {
return ImageList.size();
}
@Override
public Object getItem(int position) {
return ImageList.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
public void add(General general) {
ImageList.add(general);
}
private class ViewHolder {
TextView Thing;
ImageView ThingImage;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = new ViewHolder();
if (convertView == null) {
// convertView = layoutInflater.inflate(R.layout.gridgeneral, null);
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.image_general, null);
holder.ThingImage = (ImageView) convertView.findViewById(R.id.imageView_flag1);
holder.Thing = (TextView) convertView.findViewById(R.id.thing1);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
// General general = ImageList.get(position);
General general=(General) this.getItem(position);
holder.Thing.setText(general.getName());
byte[] thingName = general.getImage();
Bitmap bitmap = BitmapFactory.decodeByteArray(thingName, 0, thingName.length);
holder.ThingImage.setImageBitmap(bitmap);
return convertView;
}
}