2016-12-21 4 views
-1

ボタンバックカウントとボタンをアクティブにして、新しいアクティビティを開きます。
私のアプリの新しいことをしようとしています。 (私は間質が追加され、そのメイクボタンのカウントを待つ表示する必要があり。)ボタンとボタンを3から0まで数えます。

方法A

  1. ユーザーは、Active 3. 2. 1. 0
  2. ボタンを数えるボタン
  3. ボタンをクリックします! (その後、ボタンやオープン次/新しい活動などをクリックしてください。)

方法B

  1. ユーザーはアプリ/ OnCreate関数が... 3. 2. 1をカウント
  2. ボタンを開始開きます。0
  3. ボタンアクティブ!

これは助けてください行うことができ、コードや方法

(... ..]ボタンをクリックし、[次へ/新しい活動などを開きます)。ありがとう:)

+0

あなたがその外の時間を設定しようとしているが、間質で、ユーザの外観を強制するために、ボタン上に表示されますか? –

答えて

1

このコードを試してみてください。トーストの代わりに、次のアクティビティに意図を渡して、2番目のアクティビティでこの同じコードを貼り付けてください。

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); 
} 
} 

//activity_main.xml

<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

それは本当にありがとう –

関連する問題