-
i am looking to read from a sqlite database. database holds byte array info from an image(blob type).
- convert the byte array into a bmp.
- store that bmp in an int array.
Story: i have entered an image into a database from an image view when the image changes in that image view i can save it to the sqlite database. i convert it into a byte Array and in it goes at the push of a button.
Now i want to view all the images that i have stored in that database. I have used a PagerAdapter to view items that are already in my drawable folder as follows
private int[] image_resources = {R.drawable.community_btn_txtpn,R.drawable.logo_design,R.drawable.photo_camerabtn_txt, R.drawable.plant_for_gallery,R.drawable.save_for_sharing_txt,R.drawable.seed_savebtn_txt,R.drawable.seed_sharebtn_txt, R.drawable.seeds_for_sharing_txt};
i need that array to hold the images form my database.
and code from the database query to read from the database. i have gotten this far
public Cursor getImage(){
SQLiteDatabase db = this.getReadableDatabase();
Cursor C = db.rawQuery("select image from " + TABLE_IMAGE,null);
return C;
}
code from the PagerAdapter
package com.jonnyg.gardenapp;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
/**
* Created by reiko_000 on 24/04/2016.
*/
public class CustomSwipeAdapter extends PagerAdapter {
private int[] image_resources = {R.drawable.community_btn_txtpn,R.drawable.logo_design,R.drawable.photo_camerabtn_txt,
R.drawable.plant_for_gallery,R.drawable.save_for_sharing_txt,R.drawable.seed_savebtn_txt,R.drawable.seed_sharebtn_txt,
R.drawable.seeds_for_sharing_txt};
private Context ctx;
private LayoutInflater layoutInflater;
public CustomSwipeAdapter(Context ctx){
this.ctx = ctx;
}
@Override
public int getCount() {
return image_resources.length;
}
@Override
public boolean isViewFromObject(View view, Object object) {
return (view ==(RelativeLayout)object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
layoutInflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View item_view = layoutInflater.inflate(R.layout.swipe_layout,container,false);
ImageView imageView = (ImageView)item_view.findViewById(R.id.image_view_gallery);
TextView textView = (TextView)item_view.findViewById(R.id.image_count);
TextView photoSlide = (TextView)item_view.findViewById(R.id.txtVPhotoSlide);
imageView.setImageResource(image_resources[position]);
textView.setText("Image : " + position);
container.addView(item_view);
return item_view;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
//work faster
container.removeView((RelativeLayout)object);
}
}
Aucun commentaire:
Enregistrer un commentaire