Android学习第三天--listview方式六
mainactivity.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <ListView android:id="@+id/listview1" android:layout_width="match_parent" android:layout_height="wrap_content"/> </RelativeLayout>
一个用来放置listview里面内容的xml
<?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:textSize="50sp"/>
java代码
import java.util.ArrayList; import java.util.List; import android.app.Activity; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.SimpleAdapter; public class MainActivity extends Activity { String [] address ={"上海","广州"}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ListView listView=(ListView)findViewById(R.id.listview1); ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this, R.layout.activity_main_lv, address); listView.setAdapter(arrayAdapter); } }