80,351
社区成员
发帖
与我相关
我的任务
分享
public class listviewmain extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.btn);
btn.setOnClickListener(new btn_lin());
ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
HashMap<String, String> map1 = new HashMap<String, String>();
HashMap<String, String> map2 = new HashMap<String, String>();
HashMap<String, String> map3 = new HashMap<String, String>();
map1.put("name", "aaa");
map1.put("ip", "192.168.0.0");
map2.put("name", "bbb");
map2.put("ip", "192.168.0.1");
map3.put("name", "ccc");
map3.put("ip", "192.168.0.2");
list.add(map1);
list.add(map2);
list.add(map3);
SimpleAdapter listadapter = new SimpleAdapter(this, list,
R.layout.user, new String[] { "name", "ip" }, new int[] {
R.id.name, R.id.ip });
setListAdapter(listadapter);
}
private class btn_lin implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
finish();
}
}
}
<?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"
>
<ListView android:id="@+id/listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawSelectorOnTop="false"
android:scrollbars="vertical"
/>
<Button android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/name"
android:layout_width="180dip"
android:layout_height="30dip"
android:singleLine="true"
/>
<TextView android:id="@+id/ip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>