I have simple code of an Asynctask which is to set and image to imageview after loading from Database. i Call this class in onCreateView of my fragment but image isn't in imageview. Note - That table has only one row so i think nothing's wrong with the query.
protected class setpro extends AsyncTask<String, String, Bitmap> {
@Override
protected Bitmap doInBackground(String... params) {
//Set profile
DataBaseOperations hell = new DataBaseOperations(getActivity());
SQLiteDatabase db = hell.getReadableDatabase();
String[] columns = {mDatabase.Tableinfo.Pic};
Cursor cur = db.query(mDatabase.Tableinfo.Table_Name, columns, null, null, null, null, null);
byte[] b = null;
Bitmap bp = null;
while (cur.moveToNext()) {
b = cur.getBlob(cur.getColumnIndex(mDatabase.Tableinfo.Pic));
}
if (b.length > 0) {
bp = BitmapFactory.decodeByteArray(b, 0, b.length);
cur.close();
db.close();
hell.close();
}
return bp;
}
@Override
protected void onPostExecute(Bitmap result) {
if(result != null){
ImageView iv = (ImageView) mview.findViewById(R.id.pro);
iv.setImageBitmap(result);
}
}
and here is my calling code.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mview = inflater.inflate(R.layout.fragment_profile, container, false);
Button Setprofile = (Button) mview.findViewById(R.id.setprofile);
// set profile pic
new setpro().execute("whatever");
}
Aucun commentaire:
Enregistrer un commentaire