一、继承ListActivity
package cn.edu.ui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.SimpleAdapter;
public class Mp3PlayerActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
List<Map<String,String>> list=new ArrayList<Map<String,String>>();
Map<String,String> map1=new HashMap<String,String>();
map1.put("name", "Hello");
map1.put("size", "1000");
list.add(map1);
SimpleAdapter simpleAdapter=new SimpleAdapter(this,list,R.layout.mylistview,new String []{"name","size"},new int [] {R.id.name,R.id.size});
setListAdapter(simpleAdapter);
}
}
二、配置main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ListView android:id="@id/android:list" android:drawSelectorOnTop="false" android:layout_width="fill_parent" android:layout_height="wrap_content" android:scrollbars="vertical"/> </LinearLayout>
三、增加mylistview.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <TextView android:id="@+id/size" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> </LinearLayout>