我正在尝试使用TwoLineListItem,我的类没有扩展ListActivity,只是扩展了Activity类。
布局文件如下所示;
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/seealllayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip">
<TwoLineListItem
android:id="@+id/SeeAllList"
android:paddingTop="2dip"
android:paddingBottom="2dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:mode="oneLine"
>
<TextView
android:id="@android:id/text1"
android:gravity="left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dip"
android:layout_marginTop="6dip"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
<TextView
android:id="@android:id/text2"
android:gravity="right"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dip"
android:layout_marginTop="6dip"
android:layout_marginRight="6dip"
android:layout_toRightOf="@android:id/text1"
android:textAppearance="?android:attr/textAppearanceLarge"
/>
</TwoLineListItem>
<Button
android:id="@+id/close"
android:layout_marginTop="10dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cclose" />
</LinearLayout>
在类中我将数据加载到simpleAdapter中没有任何问题,但是我无法找到将此数据连接到视图twolistitem的方法。如果我取消注释mlist定义,应用程序会挂起..
public class SeeAllActivity extends Activity {
private SimpleAdapter sa;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// open our layout and set the titles
setContentView(R.layout.seeall_layout);
Resources res = getResources();
String[] unitsarr = null;
String[] factorsarr = null;
factorsarr = res.getStringArray(R.array.anglefactor_array);
unitsarr = res.getStringArray(R.array.angleunits_array);
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
HashMap<String,String> item;
for(int i=0;i<factorsarr.length;i++){
item = new HashMap<String,String>();
item.put( "line1", unitsarr[i]);
item.put( "line2", factorsarr[i]);
list.add( item );
}
sa = new SimpleAdapter(this, list,
android.R.layout.two_line_list_item,
new String[] { "line1","line2" },
new int[] {android.R.id.text1, android.R.id.text2});
//ListView mListView = (ListView) findViewById(R.id.SeeAllList);
//mListView.setAdapter(new ArrayAdapter<String>(this, R.layout.seeall2_layout, sa));
//mListView.setAdapter(sa);
// putting a listener to the close button
Button close = (Button) findViewById(R.id.close);
close.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
}
由于