成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Android倒計時-創(chuàng)新互聯

感謝極客學院的視頻

成都創(chuàng)新互聯公司長期為成百上千家客戶提供的網站建設服務,團隊從業(yè)經驗10年,關注不同地域、不同群體,并針對不同對象提供差異化的產品和服務;打造開放共贏平臺,與合作伙伴共同營造健康的互聯網生態(tài)環(huán)境。為潼南企業(yè)提供專業(yè)的網站設計制作、做網站,潼南網站改版等技術服務。擁有十多年豐富建站經驗和眾多成功案例,為您定制開發(fā)。

布局文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    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="com.example.timer.MainActivity" >

    <EditText 
        android:id="@+id/inputtime"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        
        />
    
    <Button 
        android:id="@+id/settime"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="set"
        />
    
    <TextView
        android:id="@+id/showtime"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        />
    
    <LinearLayout 
        android:orientation="horizontal"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        >
        
        <Button
            android:id="@+id/starttime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="start"
            />
        
        <Button
            android:id="@+id/endtime"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="end"
            />
        
    </LinearLayout>

</LinearLayout>

下面是Java文件:

package com.example.timer;

import java.util.Timer;
import java.util.TimerTask;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity implements OnClickListener{
	
	EditText inputtime;
	Button settime,starttime,endtime;
	TextView showtime;
	private int i = 0 ;
	Timer timer = null;
	TimerTask task = null;
	
	private void init(){
		inputtime = (EditText)findViewById(R.id.inputtime);
		settime = (Button)findViewById(R.id.settime);
		starttime = (Button)findViewById(R.id.starttime);
		endtime = (Button)findViewById(R.id.endtime);
		showtime = (TextView)findViewById(R.id.showtime);
		settime.setOnClickListener(this);
		starttime.setOnClickListener(this);
		endtime.setOnClickListener(this);
	}

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

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch(v.getId()){
		case R.id.settime:
			showtime.setText(inputtime.getText().toString());
			i = Integer.parseInt(inputtime.getText().toString());
			break;
		case R.id.starttime:
			startTime();
			break;
		case R.id.endtime:
			endTime();
			break;
		}
	}
	private Handler mHandler = new Handler(){
		public void handleMessage(Message msg){
			showtime.setText(msg.arg1+"");
			startTime();
		}
	};
	
	public void startTime(){
		timer = new Timer();
		task = new TimerTask(){

			@Override
			public void run() {
				// TODO Auto-generated method stub
				i--;
				Message message = mHandler.obtainMessage();
				message.arg1 = i;
				mHandler.sendMessage(message);
			}
			
		};
		timer.schedule(task,1000);//第二個參數表示以1000毫秒計時
	}

	public void endTime(){
		timer.cancel();
	}
}
  1. 設置監(jiān)聽可以implements OnClickListener接口然后重寫onClick(View v)方法,然后給組件widget.setOnClickListener(this);然后在onClick()方法里抓取v.getId()

  2. TextView.setText(xxxx)里xxxx必須是字符串類型否則崩潰,可以用xxx.toString()也可以xxx+""自動轉化

另外有需要云服務器可以了解下創(chuàng)新互聯scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。

當前標題:Android倒計時-創(chuàng)新互聯
本文URL:http://jinyejixie.com/article10/cecggo.html

成都網站建設公司_創(chuàng)新互聯,為您提供定制開發(fā)、軟件開發(fā)、定制網站自適應網站、外貿網站建設手機網站建設

廣告

聲明:本網站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯

成都網站建設公司
新和县| 广安市| 定边县| 色达县| 象山县| 肇源县| 绍兴市| 南和县| 岢岚县| 托里县| 平果县| 郯城县| 巴里| 花莲县| 嘉峪关市| 延边| 桂平市| 潜江市| 成安县| 象州县| 鄂尔多斯市| 唐海县| 禹城市| 建水县| 舒兰市| 临沭县| 昂仁县| 新营市| 阜新市| 依安县| 东宁县| 宁阳县| 资兴市| 龙州县| 宁陵县| 高州市| 滕州市| 嘉兴市| 页游| 玛曲县| 巴南区|