Android--Timeline (ListView)

Source: Internet
Author: User

1. Achieving results

  

If the current property and the previous property are judged to be the same, no numbering information is displayed, otherwise the

2. The main thing is to make a judgment on the adapter

Bean-to-Tip

  

Package com.example.timetest;/** * Encapsulates the bean to display data---> Tip *  * @author Administrator *  */public class Tip {privat E string Name;private string time;private string Day;private string Number;public Tip () {super ();} Public Tip (string name, string time, String day,               string number) {super (); this.name = Name;this.time = Time;thi S.day = Day;this.number = number;} Public String GetName () {return name;} public void SetName (String name) {this.name = name;} Public String GetTime () {return time;} public void SetTime (String time) {this.time = time;} Public String GetDay () {return day;} public void Setday (String day) {this.day = day;} Public String GetNumber () {return number;} public void Setnumber (String number) {this.number = number;}}

Java

    

ListView = (ListView) Findviewbyid (R.id.listview); List < tip > list = new ArrayList < Tip > () list.add (New Tip ("1111", "11:11", "1",                              "111111")); Ist.add (New Tip ("2222", "22:22", "1",                              "2222")), List.add ("3333", "33:33", "2",                              "3333")); Ist.add (New Tip ("4444", "44:44", "3",                              "4444")), List.add ("5555", "55:55", "3",                              "5555")); Ist.add (New Tip ("6666", "66:66", "6",                              "6666")); adapter = new ListAdapter (this, list); Listview.setadapter (adapter);

3. Adapter

  

Package Com.example.timetest;import Java.util.list;import Android.content.context;import Android.view.layoutinflater;import Android.view.view;import Android.view.viewgroup;import Android.widget.baseadapter;import Android.widget.textview;public class ListAdapter extends Baseadapter {public Context Context;private List < tip > List;public ListAdapter (context context, List < Tip > li ST) {this.context = Context;this.list = list;} @ overridepublic int GetCount () {//TODO auto-generated method Stubreturn list.size ();} @ overridepublic Tip getItem (int position) {//TODO auto-generated method Stubreturn list.get (position);} @ overridepublic long getitemid (int position) {//TODO auto-generated method Stubreturn position;}  @ overridepublic View GetView (int position, view Convertview, ViewGroup parent) {//TODO   Auto-generated method Stubviewholder holder = null;if (Convertview = = null) {Convertview = Layoutinflater.from (                           context). Inflate (R.layout.list_item,                              NULL); holder = new Viewholder (); holder.name = (TextView) convertview . Findviewbyid (r.id.name); holder.time = (TextView) convertview. findviewb Yid (r.id.time); holder.day = (TextView) convertview. Findviewbyid (r.id.day); holder.num ber = (TextView) convertview. Findviewbyid (R.id.number); Convertview.settag (holder);} else {holder = (viewholder) convertview. Gettag ();} Tip tip = list.get (position); Holder.name.setText (Tip.getname ()); Holder.time.setText (Tip.gettime ()); Holder.day                              . SetText (Tip.getday ()); Holder.number.setText (Tip.getnumber ()); if (position = = 0) {}else {if (Tip.getday ()   . Equals (List.get (position-1)                                                         . GetDay ())) {holder.day.setVisibility (view.gone);} else {holder.day.setVisibility (view.visible);}} return Convertview;} Private class Viewholder {public TextView name;public TextView time;public TextView day;public TextView number;}}

4. Layout

    

<?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=" wrap_content "android:orientation=" Horizontal > <!--day and time display-<linearlayout android:layout_width= "Wrap_content" android:layout            _height= "70DP" android:layout_marginleft= "10DP" android:orientation= "vertical" > <view            Android:layout_width= "1DP" android:layout_height= "15DP" android:layout_marginleft= "15DP" android:background= "#c7c7c7"/> <textview android:id= "@+id/day" android:layout_width            = "Wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "Center_horizontal" Android:background= "#c7c7c7" android:text= "Today"/> <view android:layout_width= "1d P "Android:layout_height= "5DP" android:layout_marginleft= "15DP" android:background= "#c7c7c7"/> <textview Android:id= "@+id/time" android:layout_width= "wrap_content" android:layout_height= "wrap_content "Android:layout_gravity=" center_horizontal "android:text="/> <view A ndroid:layout_weight= "1" android:layout_width= "1DP" android:layout_height= "15DP" Android: layout_marginleft= "15DP" android:background= "#c7c7c7"/> </LinearLayout> <!--the display of information in the middle section--&gt    ; <linearlayout android:layout_width= "match_parent" android:layout_height= "Wrap_content" Android:lay Out_gravity= "center_vertical" android:layout_marginleft= "10DP" android:layout_weight= "1" Android:orie ntation= "vertical" > <textview android:id= "@+id/name" android:layout_width= "Match_paren T "Android:layout_height= "Wrap_content" android:text= "@string/test" android:textsize= "20DP"/> &lt ; TextView android:id= "@+id/number" android:layout_width= "Match_parent" Android:layout_heig     ht= "Wrap_content" android:text= "@string/test" android:textsize= "16DP"/> </LinearLayout> <!--picture Display-<imageview android:layout_width= "wrap_content" android:layout_height= "Wrap_co Ntent "android:layout_gravity=" center_vertical "android:layout_marginright=" 10DP "android:src=" @drawa Ble/ic_launcher "/></linearlayout>

5 A little progress every day hey, come on.

Android--Timeline (ListView)

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.