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