Java
setContentView(R.layout.activity_main);
ListView listView = (ListView)this.findViewById(R.id.listView);//listView
String[] strs = new String[]{"1","2","3","4"};//listView要显示的数据
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1,strs);//listView相关数据和视图的适配器
listView.setAdapter(adapter);//进行适配
xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.cz.myapplication.MainActivity">
<ListView
android:id="@+id/listView_main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true" />
</RelativeLayout>