正常に動作しているポップアップ ボタンがあります。クリックすると消えます。しかし、ユーザーが何もアクションを起こさない場合、5 秒後にポップアップを閉じるためのコードも追加したいと思いますか? それは可能ですか?
現在のコード
final ImageButton rredButton=(ImageButton)findViewById(R.id.RredButton);
rredButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popupright, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
Button btnNxtScr = (Button)popupView.findViewById(R.id.nextscreen);
btnNxtScr.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
Intent myintent1 = new Intent(colorActivity.this,colorBlueActivity.class);
startActivity(myintent1);
}
});
popupWindow.showAtLocation(rredButton, Gravity.CENTER, 0, 0);
//---
popupWindow.setFocusable(true);
popupWindow.update();
//---
}});
これは私の更新されたコードです。なにが問題ですか?
final ImageButton rredButton=(ImageButton)findViewById(R.id.RredButton);
rredButton.setOnClickListener(new View.OnClickListener() {
private CountDownTimer mPopUpDismissTimer;
public void onClick(View arg0) {
LayoutInflater layoutInflater
= (LayoutInflater)getBaseContext()
.getSystemService(LAYOUT_INFLATER_SERVICE);
View popupView = layoutInflater.inflate(R.layout.popupright, null);
final PopupWindow popupWindow = new PopupWindow(
popupView,
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
getPopUpDismissTimer(3000, 1000);
mPopUpDismissTimer.start();
}
private void getPopUpDismissTimer(long millisInFuture, long countDownInterval) {
mPopUpDismissTimer = new CountDownTimer(millisInFuture, countDownInterval) {
@Override
public void onFinish() {
Button btnNxtScr = (Button)popupView.findViewById(R.id.nextscreen);
btnNxtScr.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
Intent myintent1 = new Intent(colorActivity.this,colorBlueActivity.class);
myintent1.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(myintent1);
};
});
popupWindow.showAtLocation(rredButton, Gravity.CENTER, 0, 0);
//---
popupWindow.setFocusable(true);
popupWindow.update();
//---
}
@Override
public void onTick(long millisUntilFinished) {
}
};
}});