我有一个 2 列的行布局,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:textSize="13sp">
<TextView android:id="@+id/TRAIN_CELL"
android:layout_width="275dip"
android:layout_height="wrap_content"/>
<ImageView android:id="@+id/TO_CELL"
android:layout_width="25dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:src="@drawable/arrow_button"/>
</LinearLayout>
一旦我从数据库中获取项目,我将它们显示在左列中,在右列中我想要一个带有箭头的小图像,表示它是一个可点击的项目。但我不确定如何使图像渲染。这是我目前填充该列表的方式:
我有这两个变量:
private List<HashMap<String, String>> fillMaps;
private SimpleAdapter adapter;
起初我是这样设置它们的:
list = (ListView) findViewById(android.R.id.list);
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
//HashMap<String, String> map = new HashMap<String, String>();
// My data
fillMaps = new ArrayList<HashMap<String, String>>();
adapter = new SimpleAdapter(this, fillMaps, R.layout.questions_list,
new String[] {"train", "to"},
new int[] {R.id.TRAIN_CELL, R.id.TO_CELL});
// This was the middle item R.id.FROM_CELL,
list.setAdapter(adapter);
list.setTextFilterEnabled(true);
当数据从服务器返回时,我会像这样填充列表:
if ( obj != null )
{
questions.clear();
for ( int i = 0; i < obj.length(); i++ )
{
HashMap<String, String> map = new HashMap<String, String>();
JSONObject o = obj.getJSONObject(i);
question_id = o.getString("question_id");
question = o.getString("question");
question_by_member_id = o.getString("member_id");
Question q = new Question ( );
q.setQuestion( question );
q.setQuestionId( question_id );
q.setQuestionByMemberId(question_by_member_id);
map.put("train", question);
//map.put("from", ">");
//map.put("to", ">");
fillMaps.add(map);
questions.add( q );
}
adapter.notifyDataSetChanged();
}
但我没有得到要渲染的图像。我认为部分问题是我使用字符串作为列表期望的数据,但我不确定如何处理图像。顺便说一句,图像始终是相同的图像。
谢谢!!:)