第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在Android中制作一個chronometer計時器

在Android中制作一個chronometer計時器

Qyouu 2019-03-19 18:19:39
我想在Android中制作一個chronometer計時器,使用了timer和sheduleAtFixedRate 方法??雌饋硐袷窃趖imer的run方法中調(diào)用textview后,程序就會出錯停止運(yùn)行。我用的是以下的代碼,哪里出錯了呢?Button boton_iniciar; TextView texto_cronometro; Timer count; int a = 0; public void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);     setContentView(R.layout.activity_cronometro);     /**********************/     boton_iniciar = (Button) findViewById(R.id.button1);     texto_cronometro = (TextView) findViewById(R.id.textView1);     count= new Timer("Contador");     boton_iniciar.setOnClickListener(new OnClickListener() {         public void onClick(View v) {             // TODO Auto-generated method stub             count.scheduleAtFixedRate(new TimerTask() {                          @Override                 public void run() {                     // TODO Auto-generated method stub                     a++;                     texto_cronometro.setText(String.valueOf(a));                 }             }, 100, 100);         }     }); }
查看完整描述

3 回答

?
藍(lán)山帝景

TA貢獻(xiàn)1843條經(jīng)驗 獲得超7個贊

更新UI線程之外的用戶界面。
用這些代碼:

<youractivityname>.this.runOnUiThread(new Runnable() {

    public void run() {
        texto_cronometro.setText(String.valueOf(a));
    }
});

代替

texto_cronometro.setText(String.valueOf(a));


查看完整回答
反對 回復(fù) 2019-04-26
  • 3 回答
  • 0 關(guān)注
  • 644 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號