0

나는이 응용 프로그램을 만들어 지금은 다른 활동 시작될 때까지 초를 표시 할 텍스트 뷰를 사용하고 싶어하지만, 나는 countdowntimer 내부 txtview을 만들었지 만 그것 Countdowntimer 텍스트 뷰

Event=new String(Edt.getText().toString()); 
final int time = Integer.parseInt(sec.getText().toString()); 

Intent myInt = new Intent(MainActivity.this,Receiver.class); 

myInt.putExtra("key",Event); 
endingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this,2,myInt,PendingIntent.FLAG_CANCEL_CURRENT); 
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE); 
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+(time*1000),pendingIntent); 

new CountDownTimer(time*1000, 1000) { 

    @Override 
    public void onTick(long millisUntilFinished) { 
    // TODO Auto-generated method stub 
     txtV.setText("Activity starts"+millisUntilFinished/1000+"seconds"); // here is the txtV which isn't shown 
    } 

    @Override 
    public void onFinish() { 
     // TODO Auto-generated method stub 

    } 
}; 

를 보여준 적이 방법을 모른다
+5

'CountDownTimer'를 시작하는 것은 어떻습니까? –

답변

1

먼저 카운터를 시작해야합니다. start method

하지만이보기를 만드는 스레드에서만보기를 변경할 수 있습니다. 여러분이 할 수있는 한 가지 방법은 post runnable on view입니다 :

CountDownTimer timer = new CountDownTimer(time*1000, 1000) { 

     @Override 
     public void onTick(long millisUntilFinished) { 
      txtV.post(new Runnable() { 
       @Override 
       public void run() { 
          txtV.setText("Activity starts"+millisUntilFinished/1000+"seconds"); // here is the txtV which isn't shown 
       } 
      }); 
     } 

     @Override 
     public void onFinish() { 
      // TODO Auto-generated method stub 

     } 
    }; 
    timer.start(); 
+0

감사합니다. 매우 도움이되었습니다 !! – Marques

+0

@Marques, 문제가 해결되면 대답을 수락 할 수 있습니다 –