나 자신을위한 타이머 애플리케이션을 만드는 동안 Android와 java를 배우고 있습니다.
이전 스레드 참조하기 Android - Controlling a task with Timer and TimerTask? 타이머를 카운트 다운하기위한 Runnable 메소드를 생성하려고합니다.
내가 붙어있는 기본적인 자바 문제는 무엇을 클래스에 postDelayed() 호출을 첨부합니까?새 개발자 - 타이머 구현과 관련된 기본 Java 질문
내 활동은 지금 TimerButtons라고, 나는이 일 것이라고 생각 : 방법 postDelayed (새의 Runnable() {}, INT가) 유형에 대한 정의되지 않은 :
package com.TimerButtons; import android.app.Activity; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.PorterDuffColorFilter; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.TextView; public class TimerButtons extends Activity { private TextView mDisplayTime; private Button mButtonStart; private Button mButtonStop; private int timeTenths = 0; private Drawable d; private PorterDuffColorFilter filter; // capture our View elements @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); filter = new PorterDuffColorFilter(Color.DKGRAY, PorterDuff.Mode.SRC_ATOP); d = findViewById(R.id.buttonStart).getBackground(); d.setColorFilter(filter); d = findViewById(R.id.buttonStop).getBackground(); d.setColorFilter(filter); mDisplayTime = (TextView) findViewById(R.id.displayTime); mButtonStart = (Button) findViewById(R.id.buttonStart); mButtonStop = (Button) findViewById(R.id.buttonStop); // add click listeners to the buttons mButtonStart.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { new Thread(r).start(); } }); mButtonStop.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { timeTenths = 0; updateDisplay(); updateSetting(); } }); // display the current time updateDisplay(); } // runtime methods below here // updates the time we display in the TextView private void updateDisplay() { mDisplayTime.setText( String.valueOf(((float)timeTenths)/10) ); } private void updateSetting() { mTensDigit.setText(String.valueOf(timeTenths/100)); mOnesDigit.setText(String.valueOf((timeTenths%100)/10)); mTenthsDigit.setText(String.valueOf(timeTenths%10)); } Runnable r = new Runnable() { public void run() { if (timeTenths >= 1) { timeTenths -= 1; if (timeTenths != 0) mDisplayTime.postDelayed(this, 100); updateDisplay(); } } }; }
내가 오류 TimerButtons 주석 처리 된 행에 있습니다.
아무쪼록 안내해 주셔서 감사합니다!
Dave
TimerButtons이란 무엇입니까 ?? – Varun
TimerButtons 내 응용 프로그램의 활동입니다 - 최상위 ... – DBell