ArrayAdapter

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ListView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:entries="@array/books"
android:dividerHeight="2dp"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/gd"
android:textSize="11dp"
/>
<ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>

.java:
public class MainActivity extends Activity{
private ListView list2;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
list2=(ListView) findViewById(R.id.list2);
String[ ] arr={"孙悟空","猪八戒","牛魔王"};
ArrayAdapter<String> arrayAdapter=new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,arr);
list2.setAdapter(arrayAdapter);
}

}

posted @ 2016-03-26 12:02  yuxiao_l  阅读(146)  评论(0编辑  收藏  举报