数据已添加到Sqlite中,但不会显示在recyclerView中

时间:2019-03-18 18:11:49

标签: android sqlite android-recyclerview

我在sqlite中添加了文本和图像,并在日志屏幕和sqlite浏览器中进行了检查,但是当我将其检索到回收站时,仅显示文本,图像未显示

这是插入功能

fun inserData(user: User) {
        db = writableDatabase
        var values = ContentValues()
        if (user.Category.equals("CLOTHES")) {
            values.put("DESCRIPTION", "${user.Description}")
            values.put("IMAGE", "${user.Image}")

            if (values !== null) {
                db.insertOrThrow(Cloth,null,values)
                Toast.makeText(ctx,"Inserted in ${Cloth}",Toast.LENGTH_SHORT).show()
                Log.d("data","${values}")
            }

获取功能

fun ClothData(): ArrayList<User> {
            val clothData = ArrayList<User>()
            db = readableDatabase
            cursor = db.rawQuery("SELECT*FROM $Cloth",null)
            if (cursor !== null && cursor.moveToFirst()) {
                do {
                    var user = User()
                    user.Description = cursor.getString(cursor.getColumnIndex("DESCRIPTION"))
                    user.Image = cursor.getBlob(cursor.getColumnIndex("IMAGE"))
                    clothData.add(user)
                }while (cursor.moveToNext())

            }
                    return clothData
        }

RecyclerView适配器

class ClothesItemAdapter(var ctx:Context,var arrayList : ArrayList<User>) : RecyclerView.Adapter<ClothesItemAdapter.CustomeViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): CustomeViewHolder {
        val inflate = LayoutInflater.from(ctx).inflate(R.layout.row_clothesitem,null)
        return CustomeViewHolder(inflate)
    }

    override fun getItemCount(): Int {
        return arrayList.size
    }

    override fun onBindViewHolder(holder: CustomeViewHolder?, position: Int) {
        val position = arrayList[position]
        holder!!.clothText.text = position.Description
        val bitmap = BitmapFactory.decodeByteArray(position.Image,0,position.Image!!.size)
        holder.clothImage.setImageBitmap(bitmap)
    }


    inner class CustomeViewHolder(view:View) : RecyclerView.ViewHolder(view)
    {
        var clothImage = view.findViewById<ImageView>(R.id.clothImage)
        var clothText = view.findViewById<TextView>(R.id.clothText)
    }

}

I included the SS of sqlite browser below which shows the image is added in database

0 个答案:

没有答案