Android Development most common examples of finishing----(2) Customizing the ListView (Simpleadapter Implementation)

Source: Internet
Author: User

Android Development most common examples of finishing----(2) Customizing the ListView (Simpleadapter Implementation)


First, Activity

Mainactivity.java Source:


public class Mainactivity extends Activity {@Overrideprotected void onCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);//step1string[] Contentarray = new String[]{"Content 1", "Content 2 "," Content 3 "," Content 4 "," Content 5 "}; ListView LV = (ListView) Findviewbyid (r.id.lv);//step2arraylist

Second, XML layout file

(1) Mainactivity the layout of the main interface source code activity_main.xml:

<linearlayout xmlns:android= "http://schemas.android.com/apk/res/android"    android:layout_width= "Match_ Parent "    android:layout_height=" match_parent "    android:orientation=" vertical ">    <listview    Android:id= "@+id/lv" android:layout_width= "match_parent"     android:layout_height= "Wrap_content"/></ Linearlayout>
(1) The layout of the ListView List Unit source code list_item.xml:

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android "android:layout_height=" 60DP "android:gravity=" center_vertical "android:layout_width=" Match_parent " android:orientation= "Horizontal" > <linearlayout android:layout_width= "0DP" Android:layout_heigh t= "Match_parent" android:layout_weight= "2" android:gravity= "center_vertical" android:orientation= "vertical" > &L T TextView android:id= "@+id/starttimetext" android:layout_height= "Wrap_content" Android:layout_w              Idth= "Match_parent" android:text= "22:00"/> <textview android:id= "@+id/endtimetext" android:layout_height= "Wrap_content" android:layout_width= "match_parent" android:text= "23:00"/> </LinearLa yout> <imageview android:id= "@+id/separator" android:layout_weight= "1" android:layout_width= "0DP" and roid:layout_height= "Wrap_content"/> < TextView android:id= "@+id/content" android:layout_width= "0DP" android:layout_height= "Wrap_content" Android:layo ut_weight= "/> </LinearLayout>"

Iii. Related Resources

Files under res/drawable-mdpi/:


Separator.png


Four, the effect



Android Development most common examples of finishing----(2) Customizing the ListView (Simpleadapter Implementation)

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.