onCreate, MyActivity는 5 개의 TextViews를 표시합니다. 5 개의 TextView 중 하나를 터치하면 3 ~ 4 개의 TextView가 숨겨지고 빨간색과 녹색 중 하나에 색상을 지정하거나 녹색으로 색상을 지정합니다.다음 Android 활동을 어떻게 만들 수 있습니까?
모든 것을 여기까지 코딩 할 수 있습니다. 하지만 몇 초 동안 일시 중지 한 다음 5 개의 TextView를 새로운 값으로 다시 채우고 숨김을 해제하고 모두 흰색으로 만들 수 있습니까?
미리 감사드립니다. NEW EDIT NEW EDIT NEW EDIT
나는 새 프로젝트에 타이머를 시도하고 코드를 연결하고 내 질문에 덜 모호 할 수 있습니다. 여기
는 main.xml에 여기<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="@+id/hello"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
인 TestTimer.java
package com.somecompany.android.testtimer;
import java.util.Timer;
import java.util.TimerTask;
import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;
public class TestTimer extends Activity {
TextView hello;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
hello = (TextView)findViewById(R.id.hello);
hello.setTextColor(Color.rgb(0,255,0));
new Reminder(5);
}
void resetAndContinue() {
Log.d("TESTTIMER", "Start resetAndContinue...");
hello.setTextColor(Color.rgb(255,255,255));
Log.d("TESTTIMER", "End resetAndContinue...");
}
class Reminder {
Timer timer;
public Reminder(int seconds) {
timer = new Timer();
timer.schedule(new RemindTask(), seconds*1000);
}
class RemindTask extends TimerTask {
public void run() {
Log.d("TESTTIMER", "Ran TagRemindTask");
resetAndContinue();
timer.cancel(); //Terminate the timer thread
}
}
}
}
입니다
문제는 타이머가 resetAndContinue을 실행하고 두 개의 항목을 기록합니다,하지만이 설정되지 않는다는 것입니다 TextView 색상이 녹색에서 흰색으로 바뀌면 더 이상 로그되지 않습니다.
07-15 13 : 08 : 46.894 : DEBUG/TESTTIMER (618) : Ran TagRemindTask
07-15 13 : 08 : 46.894 : DEBUG/TESTTIMER (618) : 시작 resetAndContinue ...
07-15 13 : 08 : 47.264 : DEBUG/dalvikvm (524) : GC는 해방 202 개체/8936 08 : 52.224 : 156ms
07-15 13 바이트 DEBUG/dalvikvm (210) : 귀하의 질문은 매우 일반적이고 모호하지만 GC는 43 개체/85ms
Sebi, 의견에 감사드립니다. 나는 너의 제안을했지만, 문제가 생겼다. 내가 첨부 한 코드를 보아라. – CalvinS
Handler를 사용하여이를 코딩 할 수있었습니다. – CalvinS