gpt4 book ai didi

android - 如何在 Android 的 Listview 中以 blob 形式显示存储在数据库中的图像?

转载 作者:太空狗 更新时间:2023-10-29 14:31:51 24 4
gpt4 key购买 nike

我的问题是,我正在创建一个小测验,因此我希望图像位于顶部,答案位于其下方。这一切都是在我想显示测验答案的新 Activity 中完成的。大约有 40 个问题,每个问题都有一张图片。因此,我尝试使用 HashMap 如下:-

   ListView lv = (ListView)findViewById(R.id.list1);
String[] from = new String[] {"ques","ans"};
int[] to = new int[] {R.id.ques, R.id.ans};

// prepare the list of all records
List<HashMap<String,Bitmap>> fillMaps = new ArrayList<HashMap<String,Bitmap>>();
Cursor c1 = db.getQues(4);
byte[] bb = c1.getBlob(0);
Bitmap image = BitmapFactory.decodeByteArray(bb, 0, bb.length);
//Cursor c2 = db.getAns(4);
// String ans1 ="Ans"+") "+c2.getString(0);
HashMap<String,Bitmap> map = new HashMap<String, Bitmap>();
// HashMap<String,String> map1 = new HashMap<String, String>();
map.put("ques",image);
// map1.put("ans",ans1);
fillMaps.add(map);

SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.itemsign, from, to);
lv.setAdapter(adapter);

但我找不到正确实现它的方法。此代码不起作用。它只显示一个空白页。因此,我们将不胜感激任何帮助。由于我是 android 的新手,所以请在解释时更详细。

最佳答案

嗯,我不认为 blob 是你的问题。这是 SimpleAdapter 构造函数的 javadoc:

public SimpleAdapter (Context context, List> data, int resource, String[] from, int[] to)

Since: API Level 1 Constructor Parameters

  • context The context where the View associated with this SimpleAdapter is running
  • data A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entries specified in "from"
  • resource Resource identifier of a view layout that defines the views for this list item. The layout file should include at least those named views defined in "to"
  • from A list of column names that will be added to the Map associated with each item.
  • to The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter.

你不能在 SimpleAdapter 中使用 Bitmap,它太简单了:)

关于android - 如何在 Android 的 Listview 中以 blob 形式显示存储在数据库中的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5865724/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com