ListView allows the user to scroll through the data into the screen outside the screen up and down in a sliding manner, while the data in the screen is scrolled off the screen
Usage:
data array 1 is not transmitted directly to the ListView, requires an adapter means (Adapter) to complete
2.ArrayAdapter may be adapted to specify generic data, then the constructor to be adapted to the incoming data
3.android.R.layout.simple_list_item_1 ListView is built in a layout child, there is only one TextView for displaying a text
activity_main.xml code as follows:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
MainActivity.java code as follows:
public class MainActivity extends AppCompatActivity {
private String[] data = {"0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1, data);
ListView listView = (ListView)findViewById(R.id.list_view);
//将构建好的适配器对象传进去
listView.setAdapter(adapter);
}
}