1.ListView 简单用法
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView android:id="@+id/m_listView1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
public class MainActivity extends AppCompatActivity {
private List<String> listDatas = Arrays.asList("Apple", "Banana", "Orange", "Watermelon",
"Pear", "Grape", "Pineapple", "Strawberry", "Cherry", "Mango"
, "Apple", "Banana"
, "Orange", "Watermelon"
, "Pear", "Grape",
"Pineapple"
, "Strawberry", "Cherry", "Mango");
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//ArrayAdapter的构造函数传入3个数据:1是Context 传入当前的上下文,2是ListView子项布局的ID,3是要适配的数据
//android.R.layout.simple_list_item_1,listDatas是内置的ListViewItem
ArrayAdapter<String> dapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1,listDatas);
ListView listView = findViewById(R.id.m_listView1);
listView.setAdapter(dapter);
}
}
2.自定义ListViewItem
11.Android开发环境:ListView