1
現在、次のコードを使用してカスタムダイアログを作成しています。ボタンをクリックするとダイアログが表示されますが、OKボタンをタップしてダイアログを非表示にしたいのですが、エラーが表示されません。 私は 'dialog.dissmis'を使用しました コード:ボタンクリックでカスタムダイアログを表示しない
final Dialog dialog =new Dialog(ActionBarActivity. this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_dictionary);
TextView word = (TextView)dialog.findViewById(R.id.txtWord);
final TextView wordMeaning = (TextView)dialog.findViewById(R.id.txtMeaning);
dialog.getWindow().getAttributes().windowAnimations = R.style.AnimLeftRight;
//Get Words and it's meanings.
word.setText(Dictionary.getWord());
wordMeaning.setText(Dictionary.getMeaning());
Button btntts = (Button)dialog.findViewById(R.id.btntts);
final Button ok = (Button)dialog.findViewById(R.id.btnPositive);
// Show the dialog first.
dialog.show();
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.CENTER;
dialog.getWindow().setAttributes(lp);
btntts.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String convertTextToSpeech
wordMeaning.getText().toString();
convertToSpeech = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onInit(int status) {
if(status != TextToSpeech.ERROR){
convertToSpeech.setLanguage(Locale.US);
convertToSpeech.speak(convertTextToSpeech, TextToSpeech.QUEUE_FLUSH, null, null);
}
}
});
ok.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
}
});
誰も私にはこれがカスタムダイアログボックスをコードする適切な方法であるボタンclick..thanksに
この受け入れ可能な回答を試すhttps://stackoverflow.com/questions/13341560/how-to-create-a-custom-dialog-box-in-android –