我只是想使用一个简单的适配器创建一个列表视图。setadapter 不工作。这是我的代码。我的 setcontentview 在这段代码之前,它在 oncreate 中。
ArrayList<HashMap<String,String>> arraylist = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map = new HashMap<String,String>();
map.put("CType", "Alarm");
map.put("RType", "Once");
map.put("hour", "1");
map.put("minute", "1");
map.put("second", "30");
arraylist.add(map);
String[] stringarray= new String[] {"CType", "RType", "hour","minute","second"};
int[] intarray = new int[] {R.id.clocktextviewalarmtimer,R.id.clocktextviewrepeatonce,
R.id.clocktextviewhours,R.id.clocktextviewminutes,R.id.clocktextviewseconds};
ListView clocklistview = (ListView)findViewById(R.id.clocklistview);
SimpleAdapter adapter = new SimpleAdapter(this,arraylist,R.layout.list_clock,stringarray,intarray);
clocklistview.setAdapter(adapter);
这是包含我的列表视图的 xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ListView
android:id="@+id/clocklistview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView></LinearLayout>
这是给我的 list_clock.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="3">
<TextView
android:id="@+id/clocktextviewalarmtimer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/clocktextviewrepeatonce"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="@+id/clocktextviewhours"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_weight="0.3"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/clocktextviewminutes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_weight="0.3"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="@+id/clocktextviewseconds"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_weight="0.3"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>