The difference between using the ListView in the activity in Android and using the ListView in Listactivity

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.