0
我有一个Android应用程序与Google Cloud Endpoints一起工作。我的一项活动向数据存储发送请求以获取Message
实体的列表。 该实体有一个byte[]
字段,其中包含缩略图图像。还有两个其他字段:作者和时间戳。如何使用ImageView和SimpleAdapter?
然后,该活动必须显示一个ListView,同时显示缩略图和作者以及时间戳记字段。这里是我当前的代码,只显示我的一些资源,图像和作者/时间戳字段:
messages_list_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/messages_thumbnail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginTop="7dp"
android:background="@null"
android:src="@drawable/photo" />
<TextView
android:id="@+id/messages_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/messages_thumbnail"
android:layout_marginLeft="7dp"
android:layout_toRightOf="@id/messages_thumbnail"
android:textColor="#303030" />
<TextView
android:id="@+id/messages_timestamp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/messages_thumbnail"
android:layout_alignParentRight="true"
android:layout_marginRight="7dp"
android:textColor="#303030" />
而现在的部分,我管理SimpleAdapter用哈希映射列表:
final List<HashMap<String, Object>> messages = new ArrayList<HashMap<String, Object>>();
List<Message> listmessages = messagesCollection.getItems();
for (Message message : listmessages) {
HashMap<String, Object> element;
element = new HashMap<String, Object>();
byte[] miniature = message.decodeMiniature(); //what to do with this?
element.put("AUTHOR", message.getAuthor());
element.put("TIMESTAMP", message.getTimestamp());
messages.add(element);
}
ListAdapter simpleAdapter = new SimpleAdapter(context,
messages, R.layout.messages_list_layout,
new String[] { "AUTHOR", "TIMESTAMP"},
new int[] { R.id.messages_author, R.id.messages_timestamp });
listView_messages.setAdapter(simpleAdapter);
它完美,谢谢。 – Kritias 2015-02-18 15:18:22