2016-12-21 6 views
-1

버튼 백 카운트 및 버튼 만들기가 활성화되면 새로운 활동이 열립니다 ...
내 앱에 새로운 것을 시도하고 있습니다. (I는 간질을 추가하고 메이크업 버튼에 대한 계산과 대기의 표시해야합니다.)버튼과 3에서 0으로 카운트하는 버튼을 누르십시오.

는 방법 A

  1. 사용자가 버튼을 클릭
  2. 버튼 3. 2. 1. 0
  3. 버튼 활성 계산 !

    1. 사용자가 응용 프로그램이/한 OnCreate가 시작 열립니다

    방법 B ...

  4. 버튼 3. 2. 1을 계산 (후 .. 버튼을 열고 다음/새로운 활동 등을 클릭) .
  5. 버튼 활성!

이 도움을 주시기 바랍니다 할 수있는 코드 또는 방법

(... ... 버튼을 클릭하고 다음/새로운 활동 등을 엽니 다). 고마워요 :)

+0

당신이 그가에서 간질 사용자보기를 강제로 버튼에 표시됩니다에서 시간을 설정하려고 //activity_main.xml? –

답변

1

토스트 대신에 다음 활동에 의도를 전달하고 두 번째 활동에서이 코드를 붙여 넣으면 잘 작동합니다.

import android.app.Activity; 
import android.os.Bundle; 
import android.os.CountDownTimer; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.View; 
import android.view.View.OnClickListener; 
import android.widget.Button; 
import android.widget.TextView; 
import android.widget.Toast; 

public class Sample extends Activity { 

// Declare a variable to hold count down timer's paused status 
private boolean isPaused = false; 
// Declare a variable to hold count down timer's paused status 
private boolean isCanceled = false; 

// Declare a variable to hold CountDownTimer remaining time 
private long timeRemaining = 0; 
CountDownTimer timer; 
long millisInFuture = 4000; // 30 seconds 
long countDownInterval = 1000; // 1 second 
TextView tView; 
Button btnStart; 
Button btnPause; 
Button btnResume; 
Button btnCancel; 

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

    // Get reference of the XML layout's widgets 
    tView = (TextView) findViewById(R.id.tv); 
    btnStart = (Button) findViewById(R.id.btn_start); 

    // Set a Click Listener for start button 
    btnStart.setOnClickListener(new OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      timercall(); 

      // Disable the start and pause button 
      btnStart.setEnabled(false); 

      // Initialize a new CountDownTimer instance 

     } 
    }); 

    // Set a Click Listener for pause button 

    // Set a Click Listener for resume button 

} 

private void timercall() { 
    // TODO Auto-generated method stub 
    btnStart.setEnabled(false); 
    timer = new CountDownTimer(millisInFuture, countDownInterval) { 
     public void onTick(long millisUntilFinished) { 
      // do something in every tick 
      if (isPaused || isCanceled) { 
       // If the user request to cancel or paused the 
       // CountDownTimer we will cancel the current 
       // instance 
       cancel(); 
      } else { 
       // Display the remaining seconds to app interface 
       // 1 second = 1000 milliseconds 
       tView.setText("" + millisUntilFinished/1000); 
       // Put count down timer remaining time in a variable 
       timeRemaining = millisUntilFinished; 
      } 
     } 

     public void onFinish() { 
      // Do something when count down finished 
      tView.setText("Activated"); 
      btnStart.setText("Active"); 
      btnStart.setEnabled(true); 
      btnStart.setClickable(true); 
      // Enable the start button 
      btnStart.setEnabled(true); 
      // Disable the pause, resume and cancel button 
      btnStart.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        // TODO Auto-generated method stub 
        Toast.makeText(getApplicationContext(), "next page", 
          Toast.LENGTH_SHORT).show(); 
       } 
      }); 

     } 
    }.start(); 
} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    // getMenuInflater().inflate(R.menu.menu_main, menu); 
    return true; 
} 

@Override 
public boolean onOptionsItemSelected(MenuItem item) { 
    // Handle action bar item clicks here. The action bar will 
    // automatically handle clicks on the Home/Up button, so long 
    // as you specify a parent activity in AndroidManifest.xml. 
    int id = item.getItemId(); 

    // noinspection SimplifiableIfStatement 
    /* 
    * if (id == R.id.action_settings) { return true; } 
    */ 

    return super.onOptionsItemSelected(item); 
} 
} 

<RelativeLayout 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:background="#ffffff" 
android:padding="16dp" 
tools:context=".MainActivity" > 

<TextView 
    android:id="@+id/tv" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="CountDownTimer will display here..." 
    android:textColor="#000000" /> 

<Button 
    android:id="@+id/btn_start" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_below="@id/tv" 
    android:text="Start" /> 

</RelativeLayout> 
+0

고맙습니다. HsRaja :) 시도해 보겠습니다. –

+0

정말 완벽하게 감사했습니다. –