在简单适配器中加载图像位图并在Listview Android中显示
我在一个Android活动中工作,我有列表视图,并以json格式从服务器动态加载数据,对于图像,我得到位图 我遇到的问题是在Listview中加载位图图像我如何在简单适配器中集成图像 这是我的密码: 单行xml:在简单适配器中加载图像位图并在Listview Android中显示,android,listview,bitmap,Android,Listview,Bitmap,我在一个Android活动中工作,我有列表视图,并以json格式从服务器动态加载数据,对于图像,我得到位图 我遇到的问题是在Listview中加载位图图像我如何在简单适配器中集成图像 这是我的密码: 单行xml: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:padding="@dimen/activity_horizontal_margin">
<TextView
android:id="@+id/statusp"
android:text="status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:layout_marginLeft="82dp"
android:textColor="@color/colorAccent"
android:layout_below="@+id/dspecs" />
<TextView
android:id="@+id/dspecs"
android:text="speciality"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:layout_marginLeft="82dp"
android:textColor="@color/colorAccent"
android:layout_below="@+id/usr_dname" />
<TextView
android:id="@+id/usr_dname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="2dip"
android:paddingTop="6dip"
android:textColor="@color/colorPrimaryDark"
android:textSize="20sp"
android:text="Name"
android:textStyle="bold"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/imug_p1"
android:layout_marginStart="41dp" />
<ImageView
android:id="@+id/im2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:layout_alignParentRight="true"
android:src="@drawable/arrow"/>
<ImageView
android:id="@+id/imug_p1"
android:layout_width="40dp"
android:layout_height="40dp"
android:src="@drawable/hdoc"
android:layout_above="@+id/statusp"
android:layout_alignParentStart="true" />
但是listview中没有显示任何内容
已编辑
我已经将位图转换为可绘制的,即使这样我也看不到任何图像。请检查我的更新代码。您需要为BaseAdapter的子级创建自己的适配器。这是我可以尝试使用自定义适配器的唯一解决方案。但是我的数据也没有显示,我认为我没有匹配正确的参考。通过查看我上面的代码,你能给出任何修改过的代码示例吗?我应该如何使用自定义适配器你知道recyclerview吗?是的,它比使用recyclerview要好,但我是新手,我不知道如何对其进行编码检查一旦检查,我已经检查了,lazyadapter类无法解决错误请将适配器代码作为文本发布。您现在无法引用它。请参阅代码中的编辑适配器谢谢。但您现在已更改为
R.id.imug\p
。没关系。在你有一个可抽的。
if(singleUser.has("picture")){
pic = singleUser.get("picture").toString();
byte[] decodedString = Base64.decode(pic, Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
Drawable did = new BitmapDrawable(getResources(), decodedByte);
}
HashMap<String, String> docs = new HashMap<>();
docs.put("name", key);
docs.put("speciality",speci);
docs.put("status", status);
docs.put("picture",did.toString()); ///here i am adding bitmap
contactList.add(docs);
ListAdapter adapter = new SimpleAdapter(Users.this, contactList,R.layout.user_listitem,
new String[]{"picture","name","speciality" ,"status"},
new int[]{R.id.imug_p1,R.id.usr_dname,R.id.dspecs,R.id.statusp});
usersList.setAdapter(adapter);
((BaseAdapter) adapter).notifyDataSetChanged();