Android -- 時間軸(ListView)

來源:互聯網
上載者:User

標籤:

1. 實現效果

  

  如果判斷當前的屬性和上一個屬性相同時,不顯示編號資訊 ,否則就顯示

2.  主要是在適配器上面做判斷

  bean  --> Tip

  

package com.example.timetest;/** * 封裝要顯示資料的bean ---> Tip *  * @author Administrator *  */public class Tip {private 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;this.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" ) );list.add ( new Tip ( "2222" , "22:22" , "1" ,                              "2222" ) );list.add ( new Tip ( "3333" , "33:33" , "2" ,                              "3333" ) );list.add ( new Tip ( "4444" , "44:44" , "3" ,                              "4444" ) );list.add ( new Tip ( "5555" , "55:55" , "3" ,                              "5555" ) );list.add ( new Tip ( "6666" , "66:66" , "6" ,                              "6666" ) );adapter = new ListAdapter ( this , list );listView.setAdapter ( adapter );

 3. 適配器

  

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 > list ) {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                              .findViewById ( R.id.time );holder.day = ( TextView ) convertView                              .findViewById ( R.id.day );holder.number = ( 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和time 的顯示 -->    <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="今天" />        <View            android:layout_width="1dp"            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="12:00" />        <View            android:layout_weight="1"            android:layout_width="1dp"            android:layout_height="15dp"            android:layout_marginLeft="15dp"            android:background="#c7c7c7" />    </LinearLayout>    <!-- 中間部分資訊的顯示 -->    <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:layout_gravity="center_vertical"        android:layout_marginLeft="10dp"        android:layout_weight="1"        android:orientation="vertical" >        <TextView            android:id="@+id/name"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:text="@string/test"            android:textSize="20dp" />        <TextView            android:id="@+id/number"            android:layout_width="match_parent"            android:layout_height="wrap_content"            android:text="@string/test"            android:textSize="16dp" />    </LinearLayout>    <!-- 圖片的顯示 -->    <ImageView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_gravity="center_vertical"        android:layout_marginRight="10dp"        android:src="@drawable/ic_launcher" /></LinearLayout>

 

5.  每天進步一點點  嘿嘿  加油

 

Android -- 時間軸(ListView)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.