トーストのように、一定期間画面にテキストを表示しようとしていますが、画面に表示されている正確な時間を指定する機能があります。アラートダイアログがこれで機能するかもしれないと思っていますが、ダイアログを自動的に閉じる方法がわからないようです。
トースト通知の代わりに、表示される正確な時間を指定できる方法を提案できますか?
ありがとうございました!
static DialogInterface dialog = null;
public void toast(String text, int duration) {
final AlertDialog.Builder builder = new AlertDialog.Builder(gameplay);
LayoutInflater inflater = (LayoutInflater) gameplay.getSystemService(gameplay.LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.tutorial, (ViewGroup)gameplay.findViewById(R.id.layout_root));
((TextView)layout.findViewById(R.id.message)).setText(text);
builder
.setView(layout);
builder.show();
if (dialog!=null){
dialog.cancel();
dialog.dismiss();
}
dialog = builder.create();
Handler handler = null;
handler = new Handler();
handler.postDelayed(new Runnable(){
public void run(){
dialog.cancel();
dialog.dismiss();
}
}, 500);
}