The difference and connection between activity and Listactivity using ListView in Android:
1. Use of activity:
(1). Concept:
Each activity corresponds to a display interface, and each activity is exclusive to the entire screen.
(2). Steps:
A: In an XML layout, the ListView tag ID can be arbitrarily evaluated as:
<ListView android:id="@+id/lv_show" android:layout_width="match_parent" android:layout_height="wrap_content" />
B: The ListView object is obtained through Findviewbyid in the program such as:
ListView mLv = (ListView)findViewById(R.id.lv_show);
C: Initialize the adapter object:
MyAdapter mAdapter=new MyAdapter(mContext);
D: bind data for adapter:
mLv.setAdapter(mAdapter);
2. Use of listactivity:
(1). Concept:
Listactivity class inherits activity class, A ListView (List view) interface component is bound by default and provides some actions related to List view and processing.
(2). Click event:
Each row in the ListView interface Component (Row) can be selected. We can borrow a onlistitemclick function to get the information of which column the user is selecting and do the following processing.
(3). Note:
A:listactivity is simply a combination of ListView and activity. The
B:listactivity can be used without Setcontentview (R.layout.main), which by default is a ListView full screen.
C: If you want to display other controls on the screen, such as text boxes and buttons, you can use the following methods:
A, add: Setcontentview (R.layout.main);
B, XML file: Add a ListView control and a TextView control, note that their IDs must be @id/android:list, @id/android:empty; the previous one represents a matching listview, The latter indicates a hint that appears if the ListView has no content.
(4). Step:
A : XML layout, the ListView tag ID is as follows:
<ListView android:id="@id/android:list" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@id/android:empty" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="你好" />
B: Initialize the adapter object:
MyAdapter mAdapter=new MyAdapter(mContext);
D: bind data for adapter:
mLv.setListAdapter(mAdapter);
Note:
If you want to get the ListView object in the program, use the Getlistview () method
The difference between using the ListView in the activity in Android and using the ListView in Listactivity