2016-12-02 11 views
0

SQLiteの列からデータを直接取得すると、アプリの処理が遅れる。 ImageViewを使用しているときに直接参照を画像に追加すると、うまく動作します。スレッディングはこの問題を解決するか、SQLite DBからイメージを更新する別の方法です。SQLiteの遅れから画像の値を取得するListView

私はSQLiteからデータを引き出し、ArrayListを作成しています。データが格納されているArrayListのみを使用する場合、遅れは発生しません。

 @Override // Layout displayed with the ArrayAdapter (yListAdapter) 
     public View getView(int position, View convertView, ViewGroup parent) { 

     View itemView = convertView; 
     if (itemView == null) { 
      itemView = getLayoutInflater().inflate(R.layout.listlayout11, parent, false); 
     } 

     Store1 currentPos = StoredInfo.get(position); 


     ImageView imageView1 = (ImageView) itemView.findViewById(R.id.checkBoxIMG); 


    } 

    // This doesnt work 
    imageView1.setImageResource(currentPos.getTheSelectVal()); 

    // This will work 
    // imageView1.setImageResource(R.drawable.checkYes) 
+0

このコードを試してみてください、あなたは[]バイトで画像を保存してから抽出することだと思いましたか?私はレルムを使用しています。この手順は、遅れなく、私を助けます。 –

答えて

1

// Get the image from SQLite DB 
     // We will just get the last image we just saved for convenience... 
     public byte[] retreiveImageFromDB() { 
      Cursor cur = mDb.query(true, IMAGES_TABLE, new String[]{IMAGE,}, 
            null, null, null, null, 
            IMAGE_ID + " DESC", "1"); 
      if (cur.moveToFirst()) { 
       byte[] blob = cur.getBlob(cur.getColumnIndex(IMAGE)); 
       cur.close(); 
       return blob; 
      } 
      cur.close(); 
      return null; 
     } 


    public class Utils { 

     public static byte[] getImageBytes(Bitmap bitmap) { 
      ByteArrayOutputStream stream = new ByteArrayOutputStream(); 
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); 
      return stream.toByteArray(); 
     } 

     public static Bitmap getImage(byte[] image) { 
      return BitmapFactory.decodeByteArray(image, 0, image.length); 
     } 

     public static byte[] getBytes(InputStream inputStream) throws IOException { 
      ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); 
      int bufferSize = 1024; 
      byte[] buffer = new byte[bufferSize]; 

      int len = 0; 
      while ((len = inputStream.read(buffer)) != -1) { 
       byteBuffer.write(buffer, 0, len); 
      } 
      return byteBuffer.toByteArray(); 
     } 

    } 
関連する問題