編輯:關於Android編程
Android中的倒計時的功能(也可以直接使用CountDownTimer這個類直接實現,相關此Demo可查看我的博客),參考了網上寫的很好的一個倒計時Demo:
下面提供下代碼,和大家一起分享一下:<喎?/kf/ware/vc/" target="_blank" class="keylink">vcD4KPHA+TWFpbkFjdGl2aXR5o7o8L3A+CjxwPjxwcmUgY2xhc3M9"brush:java;">package com.example.mytime;
import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends Activity {
Button startButton;
EditText minuteText;
EditText secondText;
int minute;
int second;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
startButton = (Button) findViewById(R.id.button_start);
minuteText = (EditText)findViewById(R.id.minute);
secondText = (EditText)findViewById(R.id.second);
startButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!minuteText.getText().toString().equals("")) {
minute = Integer.parseInt(minuteText.getText().toString());
}
if (!secondText.getText().toString().equals("")) {
second = Integer.parseInt(secondText.getText().toString());
}
if (minute != 0 || second != 0) {
ArrayList
具體倒計時相關類StartActivity:
package com.example.mytime; import java.util.ArrayList; import java.util.Timer; import java.util.TimerTask; import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.Window; import android.widget.TextView; public class StartActivity extends Activity{ static int minute = -1; static int second = -1; final static String tag = "tag"; TextView timeView; Timer timer; TimerTask timerTask; Handler handler = new Handler(){ public void handleMessage(Message msg) { System.out.println("handle!"); if (minute == 0) { if (second == 0) { timeView.setText("Time out !"); if (timer != null) { timer.cancel(); timer = null; } if (timerTask != null) { timerTask = null; } }else { second--; String minutes = String.valueOf(minute); String minute = minutes; minute = ""; if (second >= 10) { minutes = String.valueOf(minute); minute = minutes; minute = ""; timeView.setText(minute + second);/*"0"+minute + ":" + */ }else { timeView.setText(minute + "0" + second);/*"0"+minute + ":0" + */ } } }else { if (second == 0) { second =59; minute--; if (minute >= 10) { timeView.setText(minute + ":" + second); }else { timeView.setText("0"+minute + ":" + second); } }else { second--; if (second >= 10) { if (minute >= 10) { timeView.setText(minute + ":" + second); }else { timeView.setText("0"+minute + ":" + second); } }else { if (minute >= 10) { timeView.setText(minute + ":0" + second); }else { timeView.setText("0"+minute + ":0" + second); } } } } }; }; @Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); super.onCreate(savedInstanceState); setContentView(R.layout.start); timeView = (TextView)findViewById(R.id.myTime); if (minute == -1 && second == -1) { Intent intent = getIntent(); ArrayListtimes = intent.getIntegerArrayListExtra("times"); minute = times.get(0); second = times.get(1); } timeView.setText(minute + ":" + second); timerTask = new TimerTask() { @Override public void run() { Message msg = new Message(); msg.what = 0; handler.sendMessage(msg); } }; timer = new Timer(); timer.schedule(timerTask,0,1000); } @Override protected void onDestroy() { if (timer != null) { timer.cancel(); timer = null; } if (timerTask != null) { timerTask = null; } minute = -1; second = -1; super.onDestroy(); } }
微信自推出朋友圈以來就吸引了不少用戶分享生活,有用戶問朋友圈怎麼刪除多條?微信朋友圈如何一次性刪除所有內容?下面帶來微信朋友圈照片一鍵清除教程。
前言最近做了兩個開源項目,一個是Android網絡框架NoHttp,和Volley、OkHttp一樣做客戶端請求的,更多相關信息請百度哦;另一個是Android Web服
首先上效果圖,實現如下效果: @Override protected void onCreate(Bundle savedInstanceState) {
今天修復一個使用系統的方法 android.webkit.URLUtil.guessFileName(String url,String contentDispositi