最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)訂單倒計(jì)時(shí)功能

 更新時(shí)間:2017年01月23日 14:16:10   作者:哇卡卡666  
這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)訂單倒計(jì)時(shí)的相關(guān)資料,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

先上效果圖

1.activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/activity_main"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="yascn.com.timecalc.MainActivity">



 <TextView
  android:textSize="20dp"
  android:layout_centerInParent="true"
  android:id="@+id/tv_remaintime"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:textColor="#000000"
  />
</RelativeLayout>


2.MainActivity.class

package yascn.com.timecalc;

import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class MainActivity extends AppCompatActivity {


 TextView tv_remaintime;//倒計(jì)時(shí)
 private long countdownTime;//倒計(jì)時(shí)的總時(shí)間(單位:毫秒)
 private String timefromServer;//從服務(wù)器獲取的訂單生成時(shí)間
 private long chaoshitime;//從服務(wù)器獲取訂單有效時(shí)長(zhǎng)(單位:毫秒)

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  tv_remaintime = (TextView) findViewById(R.id.tv_remaintime);

  getTimeDuring();

 }


 Handler handler = new Handler();
 Runnable runnable = new Runnable() {
  @Override
  public void run() {
   countdownTime -= 1000;//倒計(jì)時(shí)總時(shí)間減1

   SimpleDateFormat minforamt = new SimpleDateFormat("mm:ss");

   String hms = minforamt.format(countdownTime);//格式化倒計(jì)時(shí)的總時(shí)間
   tv_remaintime.setText("還剩下" + hms);
   handler.postDelayed(this, 1000);
  }
 };


 private void getTimeDuring() {
  chaoshitime = 30 * 60 * 1000;//應(yīng)該從服務(wù)器獲取

  timefromServer = "2017-01-23 11:40:50";//應(yīng)該從服務(wù)器獲取
  SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  try {
   Date serverDate = df.parse(timefromServer);

   long duringTime = new Date().getTime() - serverDate.getTime();//計(jì)算當(dāng)前時(shí)間和從服務(wù)器獲取的訂單生成時(shí)間的時(shí)間差
   countdownTime = chaoshitime - duringTime;//計(jì)算倒計(jì)時(shí)的總時(shí)間

   handler.postDelayed(runnable, 1000);

  } catch (ParseException e) {
   e.printStackTrace();
  }


 }
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

旬邑县| 安龙县| 沾化县| 黎平县| 平邑县| 延庆县| 鹤峰县| 安义县| 抚宁县| 东山县| 眉山市| 彭山县| 乐安县| 浪卡子县| 南木林县| 无极县| 垦利县| 勃利县| 晋城| 米林县| 罗城| 衢州市| 田东县| 麻栗坡县| 微山县| 商城县| 沛县| 即墨市| 金湖县| 额济纳旗| 英德市| 涟源市| 宝山区| 茶陵县| 聊城市| 湟源县| 张家港市| 藁城市| 陆丰市| 绥阳县| 龙江县|