码迷,mamicode.com
首页 > 移动开发 > 详细

Android订票系统订票功能实现(特效点击按钮实现票数自动加减1)

时间:2016-08-19 17:32:37      阅读:254      评论:0      收藏:0      [点我收藏+]

标签:

要实现的效果是点击加按钮就购买分数自动加一,同时计算合计的总计


技术分享



先共享一份colors.xml的数据,比较全面,可以根据需要添加

<?xml version="1.0" encoding="UTF-8"?>
<resources>
    
     <color name="popup_main_background">#b0000000</color>
    <color name="choose_eara_item_press_color">#f4f4f4</color>
    <color name="no_color">#00000000</color>
    
    
     <color name="top_bar_normal_bg">#4ebcd3</color>
    <color name="bottom_bar_normal_bg">#2D2F31</color>
    <color name="bottom_text_color_normal">#ffffff</color>
    <color name="divider_list">#cccccc</color>
    <color name="common_bg">#fcfcfc</color>
    <color name="topbar_bg">#0099ff</color>
    <color name="tab_bg">#f9f9f9</color>
    <color name="tab_text_bg">#bababa</color>
    <color name="line_bg">#f0f0f0</color>    
    
     <!-- 特别提示、重要数据等文字颜色:#004199     蓝色       “cor1 -->
    <!--  
    <color name="cor1">#004299</color>
    -->
    <color name="cor1">#0099ff</color>
    <color name="cor2">#7cbe28</color>   
     <!-- 背景 -->

    <color name="cor4">#fafafa</color>
    <color name="cor5">#cccccc</color>
    <color name="cor6">#999999</color>
    <color name="cor7">#666666</color>
    <color name="cor8">#333333</color>
    <color name="blue_start">#00338B</color>
    <color name="blue_center">#003F97</color>
    <color name="blue_end">#0B4CA4</color>
    <color name="yellow_text">#f08300</color>
    <!-- 青色按下效果颜色 -->
    <color name="green_start">#61A30C</color>
    <color name="green_center">#80C22C</color>
    <color name="green_end">#95D741</color>
    
     <!-- 右边菜单点击颜色 -->
    <color name="right_menu_unpressed">#CDCEC9</color>
    <color name="right_menu_pressed">#C3C3C3</color>
    <color name="menu_item_press">#2e000000</color>
    <color name="page_backgroup">#f2f2f2</color>
     <!-- 橙色 -->
    <color name="orange_color">#de6838</color>
        
        
    <!-- 灰色 -->
    <color name="grey_color1">#333333</color>
    <color name="grey_color2">#666666</color>
    <color name="grey_color3">#999999</color>

    <!-- footer、标题、下拉列表、按钮等文字颜色:#fafafa  白色 “cor4” -->
    <color name="white2">#fafafa</color>

    <!-- 正常略黑的位子颜色 -->
    <color name="textcolor">#666666</color>

    <!-- 所有线框的标准色 -->
    <color name="linecolor">#cccccc</color>
    <color name="colorhint">#cccccc</color>
    <color name="shape_start">#02367D</color>
    <color name="shape_end">#0F438A</color>
    <color name="light_gray">#EFEFEF</color>
    <color name="red1">#EB321B</color>

    <!-- capture -->
    <color name="viewfinder_mask">#60000000</color>
    <color name="result_view">#b0000000</color>
    <color name="viewfinder_frame">#ff000000</color>
    <color name="viewfinder_laser">#ffff0000</color>
    <color name="possible_result_points">#c0ffff00</color>
    <color name="linkblue">#33B5E5</color>
    
      
        
      <!-- 白色 -->
    <color name="bg_White">#FFFFFF</color>
    <!-- 黑色 -->
    <color name="bg_Black">#000000</color>
    <!-- 灰色 -->
    <color name="bg_Gray">#CCCCCC</color>

    <!-- 浅灰色 -->
    <color name="bg_Gray_light">#EEEEEE</color>

    <!-- 白色 -->
    <color name="tv_White">#FFFFFF</color>
    <!-- 黑色 -->
    <color name="tv_Black">#000000</color>
    <!-- 红色 -->
    <color name="tv_Red">#CC0000</color>
    <!-- 灰色 -->
    <color name="tv_Gray">#CCCCCC</color>
    
    
    
    
    
    
    <color name="white">#FFFFFF</color>
    <!-- 白色 -->
    <color name="ivory">#FFFFF0</color>
    <!-- 象牙色 -->
    <color name="lightyellow">#FFFFE0</color>
    <!-- 亮黄色 -->
    <color name="yellow">#FFFF00</color>
    <!-- 黄色 -->
    <color name="snow">#FFFAFA</color>
    <!-- 雪白色 -->
    <color name="floralwhite">#FFFAF0</color>
    <!-- 花白色 -->
    <color name="lemonchiffon">#FFFACD</color>
    <!-- 柠檬绸色 -->
    <color name="cornsilk">#FFF8DC</color>
    <!-- 米绸色 -->
    <color name="seashell">#FFF5EE</color>
    <!-- 海贝色 -->
    <color name="lavenderblush">#FFF0F5</color>
    <!-- 淡紫红 -->
    <color name="papayawhip">#FFEFD5</color>
    <!-- 番木色 -->
    <color name="blanchedalmond">#FFEBCD</color>
    <!-- 白杏色 -->
    <color name="mistyrose">#FFE4E1</color>
    <!-- 浅玫瑰色 -->
    <color name="bisque">#FFE4C4</color>
    <!-- 桔黄色 -->
    <color name="moccasin">#FFE4B5</color>
    <!-- 鹿皮色 -->
    <color name="navajowhite">#FFDEAD</color>
    <!-- 纳瓦白 -->
    <color name="peachpuff">#FFDAB9</color>
    <!-- 桃色 -->
    <color name="gold">#FFD700</color>
    <!-- 金色 -->
    <color name="pink">#FFC0CB</color>
    <!-- 粉红色 -->
    <color name="lightpink">#FFB6C1</color>
    <!-- 亮粉红色 -->
    <color name="orange">#FFA500</color>
    <!-- 橙色 -->
    <color name="lightsalmon">#FFA07A</color>
    <!-- 亮肉色 -->
    <color name="darkorange">#FF8C00</color>
    <!-- 暗桔黄色 -->
    <color name="coral">#FF7F50</color>
    <!-- 珊瑚色 -->
    <color name="hotpink">#FF69B4</color>
    <!-- 热粉红色 -->
    <color name="tomato">#FF6347</color>
    <!-- 西红柿色 -->
    <color name="orangered">#FF4500</color>
    <!-- 红橙色 -->
    <color name="deeppink">#FF1493</color>
    <!-- 深粉红色 -->
    <color name="fuchsia">#FF00FF</color>
    <!-- 紫红色 -->
    <color name="magenta">#FF00FF</color>
    <!-- 红紫色 -->
    <color name="red">#FF0000</color>
    <!-- 红色 -->
    <color name="oldlace">#FDF5E6</color>
    <!-- 老花色 -->
    <color name="lightgoldenrodyellow">#FAFAD2</color>
    <!-- 亮金黄色 -->
    <color name="linen">#FAF0E6</color>
    <!-- 亚麻色 -->
    <color name="antiquewhite">#FAEBD7</color>
    <!-- 古董白 -->
    <color name="salmon">#FA8072</color>
    <!-- 鲜肉色 -->
    <color name="ghostwhite">#F8F8FF</color>
    <!-- 幽灵白 -->
    <color name="mintcream">#F5FFFA</color>
    <!-- 薄荷色 -->
    <color name="whitesmoke">#F5F5F5</color>
    <!-- 烟白色 -->
    <color name="beige">#F5F5DC</color>
    <!-- 米色 -->
    <color name="wheat">#F5DEB3</color>
    <!-- 浅黄色 -->
    <color name="sandybrown">#F4A460</color>
    <!-- 沙褐色 -->
    <color name="azure">#F0FFFF</color>
    <!-- 天蓝色 -->
    <color name="honeydew">#F0FFF0</color>
    <!-- 蜜色 -->
    <color name="aliceblue">#F0F8FF</color>
    <!-- 艾利斯兰 -->
    <color name="khaki">#F0E68C</color>
    <!-- 黄褐色 -->
    <color name="lightcoral">#F08080</color>
    <!-- 亮珊瑚色 -->
    <color name="palegoldenrod">#EEE8AA</color>
    <!-- 苍麒麟色 -->
    <color name="violet">#EE82EE</color>
    <!-- 紫罗兰色 -->
    <color name="darksalmon">#E9967A</color>
    <!-- 暗肉色 -->
    <color name="lavender">#E6E6FA</color>
    <!-- 淡紫色 -->
    <color name="lightcyan">#E0FFFF</color>
    <!-- 亮青色 -->
    <color name="burlywood">#DEB887</color>
    <!-- 实木色 -->
    <color name="plum">#DDA0DD</color>
    <!-- 洋李色 -->
    <color name="gainsboro">#DCDCDC</color>
    <!-- 淡灰色 -->
    <color name="crimson">#DC143C</color>
    <!-- 暗深红色 -->
    <color name="palevioletred">#DB7093</color>
    <!-- 苍紫罗兰色 -->
    <color name="goldenrod">#DAA520</color>
    <!-- 金麒麟色 -->
    <color name="orchid">#DA70D6</color>
    <!-- 淡紫色 -->
    <color name="thistle">#D8BFD8</color>
    <!-- 蓟色 -->
    <color name="lightgray">#D3D3D3</color>
    <!-- 亮灰色 -->
    <color name="lightgrey">#D3D3D3</color>
    <!-- 亮灰色 -->
    <color name="tan">#D2B48C</color>
    <!-- 茶色 -->
    <color name="chocolate">#D2691E</color>
    <!-- 巧可力色 -->
    <color name="peru">#CD853F</color>
    <!-- 秘鲁色 -->
    <color name="indianred">#CD5C5C</color>
    <!-- 印第安红 -->
    <color name="mediumvioletred">#C71585</color>
    <!-- 中紫罗兰色 -->
    <color name="silver">#C0C0C0</color>
    <!-- 银色 -->
    <color name="darkkhaki">#BDB76B</color>
    <!-- 暗黄褐色 -->
    <color name="rosybrown">#BC8F8F</color>
    <!-- 褐玫瑰红 -->
    <color name="mediumorchid">#BA55D3</color>
    <!-- 中粉紫色 -->
    <color name="darkgoldenrod">#B8860B</color>
    <!-- 暗金黄色 -->
    <color name="firebrick">#B22222</color>
    <!-- 火砖色 -->
    <color name="powderblue">#B0E0E6</color>
    <!-- 粉蓝色 -->
    <color name="lightsteelblue">#B0C4DE</color>
    <!-- 亮钢兰色 -->
    <color name="paleturquoise">#AFEEEE</color>
    <!-- 苍宝石绿 -->
    <color name="greenyellow">#ADFF2F</color>
    <!-- 黄绿色 -->
    <color name="lightblue">#ADD8E6</color>
    <!-- 亮蓝色 -->
    <color name="darkgray">#A9A9A9</color>
    <!-- 暗灰色 -->
    <color name="darkgrey">#A9A9A9</color>
    <!-- 暗灰色 -->
    <color name="brown">#A52A2A</color>
    <!-- 褐色 -->
    <color name="sienna">#A0522D</color>
    <!-- 赭色 -->
    <color name="darkorchid">#9932CC</color>
    <!-- 暗紫色 -->
    <color name="palegreen">#98FB98</color>
    <!-- 苍绿色 -->
    <color name="darkviolet">#9400D3</color>
    <!-- 暗紫罗兰色 -->
    <color name="mediumpurple">#9370DB</color>
    <!-- 中紫色 -->
    <color name="lightgreen">#90EE90</color>
    <!-- 亮绿色 -->
    <color name="darkseagreen">#8FBC8F</color>
    <!-- 暗海兰色 -->
    <color name="saddlebrown">#8B4513</color>
    <!-- 重褐色 -->
    <color name="darkmagenta">#8B008B</color>
    <!-- 暗洋红 -->
    <color name="darkred">#8B0000</color>
    <!-- 暗红色 -->
    <color name="blueviolet">#8A2BE2</color>
    <!-- 紫罗兰蓝色 -->
    <color name="lightskyblue">#87CEFA</color>
    <!-- 亮天蓝色 -->
    <color name="skyblue">#87CEEB</color>
    <!-- 天蓝色 -->
    <color name="gray">#808080</color>
    <!-- 灰色 -->
    <color name="grey">#808080</color>
    <!-- 灰色 -->
    <color name="olive">#808000</color>
    <!-- 橄榄色 -->
    <color name="purple">#800080</color>
    <!-- 紫色 -->
    <color name="maroon">#800000</color>
    <!-- 粟色 -->
    <color name="aquamarine">#7FFFD4</color>
    <!-- 碧绿色 -->
    <color name="chartreuse">#7FFF00</color>
    <!-- 黄绿色 -->
    <color name="lawngreen">#7CFC00</color>
    <!-- 草绿色 -->
    <color name="mediumslateblue">#7B68EE</color>
    <!-- 中暗蓝色 -->
    <color name="lightslategray">#778899</color>
    <!-- 亮蓝灰 -->
    <color name="lightslategrey">#778899</color>
    <!-- 亮蓝灰 -->
    <color name="slategray">#708090</color>
    <!-- 灰石色 -->
    <color name="slategrey">#708090</color>
    <!-- 灰石色 -->
    <color name="olivedrab">#6B8E23</color>
    <!-- 深绿褐色 -->
    <color name="slateblue">#6A5ACD</color>
    <!-- 石蓝色 -->
    <color name="dimgray">#696969</color>
    <!-- 暗灰色 -->
    <color name="dimgrey">#696969</color>
    <!-- 暗灰色 -->
    <color name="mediumaquamarine">#66CDAA</color>
    <!-- 中绿色 -->
    <color name="cornflowerblue">#6495ED</color>
    <!-- 菊兰色 -->
    <color name="cadetblue">#5F9EA0</color>
    <!-- 军兰色 -->
    <color name="darkolivegreen">#556B2F</color>
    <!-- 暗橄榄绿 -->
    <color name="indigo">#4B0082</color>
    <!-- 靛青色 -->
    <color name="mediumturquoise">#48D1CC</color>
    <!-- 中绿宝石 -->
    <color name="darkslateblue">#483D8B</color>
    <!-- 暗灰蓝色 -->
    <color name="steelblue">#4682B4</color>
    <!-- 钢兰色 -->
    <color name="royalblue">#4169E1</color>
    <!-- 皇家蓝 -->
    <color name="turquoise">#40E0D0</color>
    <!-- 青绿色 -->
    <color name="mediumseagreen">#3CB371</color>
    <!-- 中海蓝 -->
    <color name="limegreen">#32CD32</color>
    <!-- 橙绿色 -->
    <color name="darkslategray">#2F4F4F</color>
    <!-- 暗瓦灰色 -->
    <color name="darkslategrey">#2F4F4F</color>
    <!-- 暗瓦灰色 -->
    <color name="seagreen">#2E8B57</color>
    <!-- 海绿色 -->
    <color name="forestgreen">#228B22</color>
    <!-- 森林绿 -->
    <color name="lightseagreen">#20B2AA</color>
    <!-- 亮海蓝色 -->
    <color name="dodgerblue">#1E90FF</color>
    <!-- 闪兰色 -->
    <color name="midnightblue">#191970</color>
    <!-- 中灰兰色 -->
    <color name="aqua">#00FFFF</color>
    <!-- 浅绿色 -->
    <color name="cyan">#00FFFF</color>
    <!-- 青色 -->
    <color name="springgreen">#00FF7F</color>
    <!-- 春绿色 -->
    <color name="lime">#00FF00</color>
    <!-- 酸橙色 -->
    <color name="mediumspringgreen">#00FA9A</color>
    <!-- 中春绿色 -->
    <color name="darkturquoise">#00CED1</color>
    <!-- 暗宝石绿 -->
    <color name="deepskyblue">#00BFFF</color>
    <!-- 深天蓝色 -->
    <color name="darkcyan">#008B8B</color>
    <!-- 暗青色 -->
    <color name="teal">#008080</color>
    <!-- 水鸭色 -->
    <color name="green">#7cbe28</color>
    <!-- 绿色 -->
    <color name="darkgreen">#006400</color>
    <!-- 暗绿色 -->
    <color name="blue">#004299</color>
    <!-- 蓝色 -->
    <color name="mediumblue">#0000CD</color>
    <!-- 中兰色 -->
    <color name="darkblue">#00008B</color>
    <!-- 暗蓝色 -->
    <color name="navy">#000080</color>
    <!-- 海军色 -->
    <color name="black">#000000</color>
    <!-- 黑色 -->
</resources>


自定义的dimens.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
	
     <!-- Default screen margins, per the Android Design guidelines. -->
      <dimen name="image_thumbnail_size">100dp</dimen>
    <dimen name="image_thumbnail_spacing">1dp</dimen>
      <dimen name="height_top_bar">48dp</dimen>
    <dimen name="activity_horizontal_margin">16dp</dimen>
    <dimen name="activity_vertical_margin">16dp</dimen>
    <dimen name="f26">18sp</dimen>
    <dimen name="f21">15sp</dimen>
    <dimen name="f18">13sp</dimen>
    <dimen name="f16">11sp</dimen>
    <dimen name="f13">9sp</dimen>
    <dimen name="f24">17sp</dimen>
    <dimen name="spa10">67dp</dimen>
    <dimen name="spa74">50dp</dimen>
    <dimen name="spa72">49dp</dimen>
    <dimen name="spa78">53dp</dimen>
    <dimen name="spa82">55dp</dimen>
    <dimen name="spa66">44dp</dimen>
    <dimen name="spa68">45dp</dimen>
    <dimen name="spa60">40dp</dimen>
    <dimen name="spa100">67dp</dimen>
    <dimen name="spa120">80dp</dimen>
    <dimen name="spa600">400dp</dimen>
    <dimen name="spa150">100dp</dimen>
    <dimen name="spa180">120dp</dimen>
    <dimen name="spa48">45dp</dimen>
    <dimen name="spa33">30dp</dimen>
    <dimen name="spa22">16dp</dimen>
    <dimen name="spa390">270dp</dimen>
    <dimen name="spa90">60dp</dimen>
    <dimen name="spa18">12dp</dimen>
    <dimen name="spa15">10dp</dimen>
    <dimen name="spa3">3dp</dimen>
    <dimen name="spa230">155dp</dimen>
    <dimen name="spa260">174dp</dimen>
    <dimen name="spa130">87dp</dimen>
    <dimen name="contract">72dp</dimen>
    <!-- 投资列表中checkbox间距 -->
    <dimen name="investment_chekbox_pandding">6dp</dimen>

    <!-- 边距 -->
    <dimen name="pad5">3dp</dimen>
    <dimen name="pad1">4dp</dimen>
    <dimen name="pad3">6dp</dimen>
    <dimen name="pad4">12dp</dimen>
    <dimen name="pad15">10dp</dimen>
    <dimen name="pad20">14dp</dimen>
    <dimen name="pad9">6dp</dimen>
    <dimen name="pad12">9dp</dimen>
    
        
   <!-- 字体大小 -->
    <dimen name="txt_8">8sp</dimen>
    <dimen name="txt_10">10sp</dimen>
    <dimen name="txt_12">12sp</dimen>
    <dimen name="txt_14">14sp</dimen>
    <dimen name="txt_16">16sp</dimen>
    <dimen name="txt_18">18sp</dimen>
    <dimen name="txt_20">20sp</dimen>
    <dimen name="txt_22">22sp</dimen>
    <dimen name="txt_24">24sp</dimen>
    <dimen name="txt_26">26sp</dimen>
    <dimen name="txt_28">28sp</dimen>
    
</resources>

自定义的drawable

text_angle_gray.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 连框颜色值 -->
    <item>
        <shape>
            <solid android:color="#CCCCCC" />
        </shape>
    </item>
    <!-- 主体背景颜色值 -->
    <item
        android:bottom="1dp"
        android:top="1dp"
        android:left="1dp"
        >
        <!-- 边框里面背景颜色 白色 -->
        <shape>
            <solid android:color="@color/page_backgroup" />
        </shape>
    </item>

</layer-list>


text_angle.xml,是实现圆角效果的

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FFFFFFFF"/>
     <corners android:radius="0dp"/>
    <stroke 
        android:color="#CCCCCC"
        android:width="0.01dp" />
</shape>

text_angle_right.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <!-- 连框颜色值 -->
    <item>
        <shape>
            <solid android:color="#CCCCCC" />
        </shape>
    </item>
    <!-- 主体背景颜色值 -->
    <item
        android:bottom="1dp"
        android:top="1dp"
        android:right="1dp"
        >
        <!-- 边框里面背景颜色 白色 -->
        <shape>
            <solid android:color="@color/page_backgroup" />
        </shape>
    </item>

</layer-list>


然后,实现这个ui

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/bg_White"
    android:focusable="true"
    android:focusableInTouchMode="true" >


    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="@dimen/height_top_bar"
        android:background="@color/top_bar_normal_bg"
        android:gravity="center_vertical" >

        <TextView
            android:id="@+id/tv_back"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:background="@drawable/common_tab_bg"
            android:clickable="true"
            android:drawableLeft="@drawable/btn_titlebar_back"
            android:gravity="center"
            android:scaleType="centerInside"
            android:text="@string/back"
            android:textColor="@color/white" />

        <TextView
            android:id="@+id/message_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="@string/reserve"
            android:textColor="@color/bottom_text_color_normal"
            android:textSize="18sp" />
    </RelativeLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/bg_Gray" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="50dp" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/tv_intro"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="2.64"
                android:paddingBottom="15dp"
                android:paddingLeft="10dp"
                android:paddingTop="15dp"
                android:textColor="@color/tv_Black" />

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:background="@drawable/line" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="38dp"
                android:orientation="horizontal" >

                <TextView
                    android:id="@+id/iv_adapter_list_pic"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="5dp"
                    android:scaleType="centerCrop"
                    android:text="出游日期:"
                    android:textColor="@color/black" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:orientation="vertical" >

                    <EditText
                        android:id="@+id/et_time"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:paddingLeft="15dp"
                        android:paddingRight="15dp"
                        android:textColor="@color/tv_Black" >
                    </EditText>
                </LinearLayout>

                <LinearLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="5dp"
                    android:orientation="vertical" >
                </LinearLayout>
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="10dp"
                android:background="@drawable/line" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="42dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <LinearLayout
                    android:id="@+id/linearLayout1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_centerVertical="true"
                    android:layout_marginRight="15dp"
                    android:orientation="horizontal" >

                    <TextView
                        android:id="@+id/tv_reduce"
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:background="@drawable/text_angle_gray"
                        android:gravity="center"
                        android:text="-"
                        android:textColor="@color/grey_color1"
                        android:textSize="@dimen/txt_12" />

                    <TextView
                        android:id="@+id/tv_num"
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:background="@drawable/text_angle"
                        android:gravity="center"
                        android:singleLine="true"
                        android:text="1"
                        android:textColor="@color/grey_color1"
                        android:textSize="@dimen/txt_12" />

                    <TextView
                        android:id="@+id/tv_add"
                        android:layout_width="25dp"
                        android:layout_height="25dp"
                        android:background="@drawable/text_angle_right"
                        android:gravity="center"
                        android:text="+"
                        android:textColor="@color/grey_color1"
                        android:textSize="@dimen/txt_12" />
                </LinearLayout>

                <TextView
                    android:id="@+id/tv_1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_centerVertical="true"
                    android:text="购买份数:"
                    android:textColor="@color/tv_Black" />

                <TextView
                    android:id="@+id/tv_price"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignBaseline="@+id/tv_1"
                    android:layout_alignBottom="@+id/tv_1"
                    android:layout_marginLeft="52dp"
                    android:layout_toRightOf="@+id/tv_1"
                    android:singleLine="true"
                    android:text="¥308.00"
                    android:textColor="@color/orange_color"
                    android:textSize="@dimen/txt_14"
                    android:textStyle="bold" />
            </RelativeLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="@color/bg_Gray_light" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="50dp"
                android:gravity="center"
                android:orientation="horizontal" >

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_marginLeft="10dp"
                    android:layout_weight="1"
                    android:text="取票信息"
                    android:textColor="@color/tv_Black" />
            </LinearLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:background="@drawable/line" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:gravity="center_vertical"
                android:paddingBottom="4dp"
                android:paddingTop="25dp" >

                <TextView
                    android:id="@+id/textView1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="21dp"
                    android:text="姓名:"
                    android:textColor="@color/tv_Black"
                    android:textSize="15sp" />

                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignTop="@+id/textView1"
                    android:layout_marginLeft="29dp"
                    android:layout_toRightOf="@+id/textView1"
                    android:background="@drawable/bg_menu_edit"
                    android:gravity="center_vertical"
                    android:hint="要与证件一样哦"
                    android:textSize="16dp" />
            </RelativeLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginLeft="8dp"
                android:layout_marginRight="8dp"
                android:background="@drawable/line" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="55dp"
                android:paddingBottom="4dp"
                android:paddingTop="25dp" >

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_alignParentTop="true"
                    android:layout_marginLeft="21dp"
                    android:text="证件:"
                    android:textColor="@color/tv_Black"
                    android:textSize="15sp" />

                <EditText
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignTop="@+id/textView2"
                    android:layout_marginLeft="29dp"
                    android:layout_toRightOf="@+id/textView2"
                    android:background="@drawable/bg_menu_edit"
                    android:hint="请输入证件号码"
                    android:textSize="16dp" />
            </RelativeLayout>

            <View
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="@color/bg_Gray_light" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="68dp"
                android:layout_weight="49.46"
                android:background="@color/bg_Gray_light"
                android:gravity="center"
                android:orientation="horizontal" >
            </LinearLayout>
        </LinearLayout>
    </ScrollView>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:layout_alignParentBottom="true"
        android:background="@color/bg_White"
        android:orientation="horizontal" >

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2.5"
            android:background="@color/bg_White"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginLeft="5dp"
                android:text="合计:"
                android:textColor="@color/purple"
                android:textSize="16sp"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/tv_total_price"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="¥0.00"
                android:textColor="@color/purple"
                android:textSize="16sp"
                android:textStyle="bold" />
        </LinearLayout>

        <TextView
            android:id="@+id/tv_clear"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/orange"
            android:clickable="true"
            android:gravity="center"
            android:text="清空"
            android:textColor="#FAFAFA" />

        <TextView
            android:id="@+id/tv_go_to_pay"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="@color/crimson"
            android:clickable="true"
            android:gravity="center"
            android:text="结算(0)"
            android:textColor="#FAFAFA" />
    </LinearLayout>

</RelativeLayout>



技术分享



业务实现

package com.tsc.activities;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.tsc.Constant;
import com.tsc.fragment.CalendarFragment;
import com.tsc.service.AddOrderService;

/**
 * 预定旅游服务的Activity类
 *  
 */
public class ReserveActivity extends Activity implements OnClickListener{
	
	private TextView tv_back;//返回的TextView
	private TextView tv_price;//单价的TextView
	private TextView tv_total_price;//总价的TextView
	private TextView tv_clear;//清空的TextView
	private TextView tv_go_to_pay;//去支付的TextView
	private TextView tv_intro;//显示线路名称的TextView
	
	
	private TextView tv_num;//显示票数的TextView
	private TextView tv_reduce;//点击可以票数减1
	private TextView tv_add;//点击可以票数加1
	
	private EditText et_time;//日历EditText,功能测试ing
	
	private Context context;//Context
	
	private String account;//获取从主界面传来的账号
	
	private double totalPrice = 0.00;//总价钱
	private int totalCount = 0;//总票数
	private String priceString;//单件,String类型的
	
	CalendarFragment calendarFragment;//日历的Fragment

	int lineID=0;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 //设置无标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_reserve);
		initView();
		initEvents();
	}
	
	/**
	 * 初始化操作
	 */
	public void initView(){
		context = this;
		
		//获取账号
		account = getIntent().getStringExtra("account");
		
		
		tv_back = (TextView)findViewById(R.id.tv_back);//返回
		tv_price = (TextView)findViewById(R.id.tv_price);//显示单价的TextView
		tv_total_price = (TextView)findViewById(R.id.tv_total_price);//显示总价钱的TextViw
		tv_clear = (TextView)findViewById(R.id.tv_clear);//点击清空,总价置0
		tv_go_to_pay = (TextView)findViewById(R.id.tv_go_to_pay);//去付款
		
		tv_num = (TextView)findViewById(R.id.tv_num);//显示票数的TextView
		tv_reduce = (TextView)findViewById(R.id.tv_reduce);//点击票数减1
		tv_add = (TextView)findViewById(R.id.tv_add);//点击票数加1
		
		et_time = (EditText)findViewById(R.id.et_time);//出游时间
		
		String tourism_time = getIntent().getExtras().getString("tourism_time");
		et_time.setText(tourism_time);
		
		double price = getIntent().getExtras().getDouble("price");
		totalCount=1;
		totalPrice = price;
		tv_price.setText("¥"+price);
		tv_total_price.setText("¥"+price);
		priceString = tv_price.getText().toString().replace("¥", "");//获取单价
		tv_num.setText("1");
		tv_go_to_pay.setText("结算(1)");
		
		lineID=getIntent().getExtras().getInt("ID");
		
		String name = getIntent().getExtras().getString("name");
		tv_intro=(TextView)findViewById(R.id.tv_intro);//线路名称
		tv_intro.setText(name);
	}
	
	
	/**
	 * 事件操作
	 */
	public void initEvents(){
		tv_back.setOnClickListener(this);
		tv_clear.setOnClickListener(this);
		tv_go_to_pay.setOnClickListener(this);
		
		tv_reduce.setOnClickListener(this);
		tv_add.setOnClickListener(this);
		
		et_time.setOnClickListener(this);
	}
	
	
	@Override
	public void onClick(View v) {
		AlertDialog alert;
		switch (v.getId())
		{
		
		case R.id.et_time:
			
			break;
	
		case R.id.tv_go_to_pay:
			if (totalCount == 0)
			{
				Toast.makeText(context, "请选择要预定的旅游服务", Toast.LENGTH_LONG).show();
				return;
			}
			alert = new AlertDialog.Builder(context).create();
			alert.setTitle("操作提示");
			alert.setMessage("总计:\n" + totalCount + "张票\n" + totalPrice + "元");
			alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener()
			{
				@Override
				public void onClick(DialogInterface dialog, int which)
				{
					return;
				}
			});
			alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener()
			{
				@Override
				public void onClick(DialogInterface dialog, int which)
				{
					String countString = String.valueOf(totalCount);//票数
					String priceString = String.valueOf(totalPrice);//单价
					String lineIdString = Integer.toString(lineID);//旅游路线ID
					String timeString = et_time.getText().toString();//出游时间
					//执行异步任务
					new AddOrderAsyncTask().execute(Constant.URL_AddOrder,account,countString,priceString,lineIdString,timeString);
				}
			});
			alert.show();
			break;
		case R.id.tv_clear:
			if (totalCount == 0)
			{
				Toast.makeText(context, "请选择要取消预定的旅游服务", Toast.LENGTH_LONG).show();
				return;
			}
			alert = new AlertDialog.Builder(context).create();
			alert.setTitle("操作提示");
			alert.setMessage("您确定要取消预定的旅游服务吗?");
			alert.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener()
			{
				@Override
				public void onClick(DialogInterface dialog, int which)
				{
					return;
				}
			});
			alert.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener()
			{
				@Override
				public void onClick(DialogInterface dialog, int which)
				{
					totalCount = 0;
					totalPrice = 0.00;
					tv_num.setText("0");
					tv_total_price.setText("¥0.00");
					tv_go_to_pay.setText("结算(0)");
				}
			});
			alert.show();
			break;
		case R.id.tv_back:
			this.finish();
			break;
		case R.id.tv_reduce:
			if(totalCount >= 1){
				totalCount--;
				tv_num.setText(String.valueOf(totalCount));
				totalPrice = Double.parseDouble(priceString)*totalCount;				
				tv_total_price.setText(String.valueOf(totalPrice));
				tv_go_to_pay.setText("结算("+totalCount+")");
			}else if(totalCount <= 0){
				Toast.makeText(context, "数量不可以小于0哦!", 1).show();
			}
			break;
		case R.id.tv_add:
			totalCount++;
			tv_num.setText(String.valueOf(totalCount));
			totalPrice = Double.parseDouble(priceString)*totalCount;
			tv_total_price.setText(String.valueOf(totalPrice));
			tv_go_to_pay.setText("结算("+totalCount+")");
			break;
		}
	
	}
	
	/**
	*
	*简介
	AsyncTask可以使得使用UI线程变的更容易更适当,它可以在后台运行一些操作然后在UI上展现,不用操作具体的线程和handlers
	一个 asynchronous task包括三种基本类型(调用参数,进度和结果),和四个步骤(调用开始,在后台运行,处理进度,结束)
	), and most often will override a second one (onPostExecute(Result).)

	使用方法描述
	Asynchronous Task必须是作为一个子类来使用,
	task实例必须在UI线程创建
	execute(Params...)必须在UI线程调用
	不要手工调用onPreExecute(), onPostExecute(Result), doInBackground(Params...), onProgressUpdate(Progress...)。
	task只可以execute一次,执行多次就报异常

	*
	*/
	class AddOrderAsyncTask extends AsyncTask<String, Void, String>{

		@Override
		protected String doInBackground(String... params) {
			AddOrderService addOrderService = new AddOrderService();
			String retStr = addOrderService.addOrder(params[0], params[1],params[2],params[3],params[4],params[5]);
			
			return retStr;
		}
		
		@Override
		protected void onPostExecute(String result) {
			// TODO Auto-generated method stub
			super.onPostExecute(result);
			if(result.equals("error")){
				Toast.makeText(getApplicationContext(), "提交订单失败!", 1).show();
			}else if(result.equals("success")){
				Toast.makeText(getApplicationContext(), "提交订单成功!", 1).show();
				ReserveActivity.this.finish();
			}
		}
		
	}

}


Android订票系统订票功能实现(特效点击按钮实现票数自动加减1)

标签:

原文地址:http://blog.csdn.net/u014427391/article/details/52252232

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!