从SQlite db获取图像路径并在新Activity中设置ImageView中的图像

时间:2016-12-08 13:22:54

标签: android image sqlite imageview android-cursoradapter

过去几天我一直在努力解决这个问题,但仍未找到解决问题的正确方法(我在这里也检查了很多类似的问题是StackOverflow,但没有一个帮助我)。 所以这是我的问题:我有一个活动,其中我有一个ImageView,我点击它时从画廊拍摄图像。这里一切正常,我在ImageView中看到了我的图像。之后,我保存了从我的图库中选择的图像的imagePath并将其放入我的SQLite数据库中。然后我有CustomCursorAdapter类,它扩展了CursorAdapter然后我想以某种方式从SQLite中使用光标检索imagePath并设置我在另一个活动中选择的图像。

PS:我不知道这是否可以通过编程方式实现,但我是这么认为的。我已经完成了我要求使用SimpleCursorAdapter的事情,但事情变得更容易了,我的任务是使用CustomCursorAdapter !我将在下面展示我的部分代码,以便更容易解释我想要实现的目标:

这里我在解码字符串

后在我的第一个活动的ImageView中设置图像
picture = (ImageView) findViewById(R.id.questionImageView);
picture.setImageBitmap(BitmapFactory.decodeFile(imgDecodableString));

然后在这里我从图库中检索imagePath并将其放入SQlite

//retrieving imagePath
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            imgDecodableString = cursor.getString(columnIndex);
            try {
                if (cursor.moveToFirst()) {
                    imagePath = cursor.getString(columnIndex);
                }
            } finally {
                cursor.close();
}
//Put imagePath in SQlite
Player player = new Player(playerName,playerLastName,playerEmail,playerDescription,imagePath);

然后我在这里丢失它:这是在我的CustomCursorAdapter类中:这应该以某种方式从SQlite db获取imagePath并将其设置为可绘制的myabe或者我不知道我的其他Activity的ImageView中的确切内容

 public void bindView(View view, Context context, Cursor cursor) {
      ImageView playerPicture = (ImageView)
            view.findViewById(R.id.questionImageView);
      //this here is not working apparently - I have a placeholder for when no image is picked from gallery and when i use the code bellow it disappears and the ImageView is just blank !
      playerPicture.setImageResource(cursor.getInt(
           cursor.getColumnIndex(DatabaseHelper.PLAYER_PICTURE)));
 }

如果需要更多代码(例如,从我的数据库中,现在让我,我会发布它) 提前致谢 !我会欣赏代码中的例子! :)

0 个答案:

没有答案
相关问题