图像中从SQLite的recyclerview未示出

问题描述 投票:0回答:1

我分别有一些数据和图像。我已经保存到sqlite的这一点。从数据库中飞出后,所有数据都显示给我,但图像不显示。我已保存的图像sqlite的罚球代码:

 holder.favoutitBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            holder.tPicture.buildDrawingCache();
            Bitmap bitmap = holder.tPicture.getDrawingCache();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
            byte[] data = baos.toByteArray();
            databaseHelper=new DatabaseHelper(context);

            boolean insert=databaseHelper.addToDb(subjects.get(position).getId(),subjects.get(position).getRoomid(),
                    subjects.get(position).getHonorname(),subjects.get(position).getRoomname(),subjects.get(position).getLocation(), subjects.get(position).getHonorphno(),
                    subjects.get(position).getPrice(),subjects.get(position).getGenralLocation() ,subjects.get(position).getLongitudeLatitude(),data, "data");
           // app:sparkbutton_inActiveImage=""
            if (insert)
            {
                Toast.makeText(context, "Data inserted into Fav", Toast.LENGTH_SHORT).show();
            }
            else {
                Toast.makeText(context, "Not inserted", Toast.LENGTH_SHORT).show();
            }
        }
    });

它是随着图像的SQLite现在,这里是从源码获取数据的代码插入数据recyclerview适配器。所有的数据被完全示出,而不是图像。

recyclerView = (RecyclerView) view.findViewById(R.id.favRoomRecyclerView);
    layoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.setHasFixedSize(true);
    db = new DatabaseHelper(getActivity());
    // int coul= Integer.parseInt(db.COL11);
    SQLiteDatabase sqLiteDatabase = db.getReadableDatabase();
    cursor = db.getData("data");
    cursor.moveToFirst();
    //Toast.makeText(this, "Id is :"+cursor.getColumnName(Integer.parseInt("ID")), Toast.LENGTH_SHORT).show();


    if (cursor.getCount() > 0) {
        do {
            byte[] blob = cursor.getBlob(cursor.getColumnIndex(db.COL11));
            ByteArrayInputStream inputStream = new ByteArrayInputStream(blob);
            Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
            RoomGetrSetr room = new RoomGetrSetr(cursor.getInt(1), cursor.getInt(2),
                    cursor.getString(3), cursor.getString(4), cursor.getString(5),
                    cursor.getString(6), cursor.getString(7), cursor.getString(8),
                    cursor.getString(9),
                    cursor.getBlob(cursor.getColumnIndex(db.COL11)));
            arrayList.add(room);
        } while (cursor.moveToNext());
        db.close();

    }

    cursor.close();
    adapter = new Fav_Room_Adapter(arrayList, getActivity());
    recyclerView.setAdapter(adapter);

getter和setter类:

 public RoomGetrSetr(int id, int roomid , String honorname, String roomname, String location,
                    String honorphno, String price, String genralLocation, String LongitudeLatitude , byte[] imgae_url) {
    this.id=id;
    this.roomid=roomid;
    this.honorname = honorname;
    this.roomname = roomname;
    this.location = location;
    this.honorphno = honorphno;
    this.price = price;
    this.genralLocation=genralLocation;
    this.LongitudeLatitude=LongitudeLatitude;
    this.imgae_url=imgae_url;
}
 public byte[] getImgae() {
    return imgae_url;
}

DatabaseHelper类

 @Override
public void onCreate(SQLiteDatabase db) {
    String createTable = "CREATE TABLE " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, " +
            COL2 + " TEXT, " + COL3 + " TEXT, " + COL4 + " TEXT, " + COL5 + " TEXT, " + COL6 + " TEXT, " + COL7 + " TEXT, " + COL8 + " TEXT, " +
            COL9 + " TEXT, " + COL10 + " TEXT, " + COL11 + " BLOB NOT NULL, " + COL12 + " TEXT )";
    db.execSQL(createTable);
    System.out.println("Table Created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int i, int i1) {
    db.execSQL("DROP IF TABLE EXISTS " + TABLE_NAME);
    onCreate(db);
}
public boolean addToDb(int id,int roomid, String honorname, String roomname,
                       String location, String honorphno,String price,String genrallocation,
                       String LongitudeLatitude, byte[] image, String user_id){
    ContentValues cv = new  ContentValues();

    System.out.println("Null pointer Exception");
    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues contentValues = new ContentValues();
    contentValues.put(COL2, id);
    contentValues.put(COL3, roomid);
    contentValues.put(COL4, honorname);
    contentValues.put(COL5, roomname);
    contentValues.put(COL6, location);
    contentValues.put(COL7, honorphno);
    contentValues.put(COL8,price);
    contentValues.put(COL9,genrallocation);
    contentValues.put(COL10,LongitudeLatitude);
    contentValues.put(COL11,image);
    contentValues.put(COL12,user_id);
    //counterForDeleteSubject=counterForDeleteSubject+1;

    System.out.println("User Id is:"+user_id);
    Log.d("DatabaseHelper", "addData: Adding to " + TABLE_NAME);

    long result = db.insert(TABLE_NAME, null, contentValues);
    //SubjectStatusChecked();
    System.out.println("Counter is --="+counterForDeleteSubject);
    ///Checking status if subject is added to SQLite then status is updated so that button is clicked




    if (result == -1) {
        return false;
    } else {
        return true;
    }
}
public Cursor getData(String userId){
    SQLiteDatabase db = this.getWritableDatabase();
    String query = "SELECT * FROM " + TABLE_NAME + " WHERE " + COL12 + " = '" + userId + "'";
    Cursor data = db.rawQuery(query, null);
    return data;
}

这里是我的适配器,用于设置数据和图像:

 @Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
    RoomGetrSetr list=subjects.get(position);
    holder.roonName.setText(subjects.get(position).getRoomname());
    holder.honorName.setText(subjects.get(position).getHonorname());
    holder.loation.setText(subjects.get(position).getLocation());
    holder.price.setText(subjects.get(position).getPrice());

现在,这里在过去的代码如何设置图像到该适配器。我在片段显示此。

android sqlite android-sqlite android-imageview
1个回答
0
投票

我对你的代码两点意见。

1.-调用方法"data"当您使用相同的用户ID databaseHelper.addToDb,那是正确的为您的使用情况?

2:你的方法onBindViewHolder不是为了将其绑定到一个ImageView的利用属性imgae_url也不类getImgae()的方法RoomGetrSetr的,我想创建这个问题,当你错过的那部分。

能否请您提供您的onBindViewHolder方法的完整代码?

© www.soinside.com 2019 - 2024. All rights reserved.