1

カスタム ダイアログを作成しようとしています。メソッドを呼び出すとsetOnClickListner、「型ビューの setOnClickListner メソッドは引数に適用できません」というメッセージが表示されます。次の行にもエラーが表示されます。

public void onClick(View v) 

「タイプ new OnClickListener(){} のメソッド onClick(View) は、スーパータイプ メソッドをオーバーライドまたは実装する必要があります」と言っています。コード:

void ReStartsFamilyFriend()
{
    // custom dialog
    // custom dialog
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.gameover);
    dialog.setTitle("Title...");

    // set the custom dialog components - text, image and button


    Button dialogButton = (Button) dialog.findViewById(R.id.butPlay);
    // if button is clicked, close the custom dialog

        //on this line below get the error "The method setOnClickListener(View.OnClickListener) in the type View is not applicable for the arguments "
    dialogButton.setOnClickListener(new OnClickListener() {
        @Override
        /*On the line below I get the error
        "The method onClick(View) of type new OnClickListener(){} must override or implement a supertype 
        method"*/
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
}   
4

1 に答える 1

0

あなたがやろうとしているのは、アラート ダイアログ以外の別のボタンを使用してアラートを単純に却下することだと思います。最良のオプションは、 VVVVVVVVVVVVVVVVVv を使用することです

    dialog.setPositiveButton (CharSequence btnText, new DialogInterface.OnClickListener listener{

    @Override
    onClick(DialogInterface dialogInter, int whichBtn){
        dialog.dismiss();
    }
    });

alertDialog.builder を使用する場合、ビューにボタンを配置する必要はありません。
こちらのリンクをご覧ください

于 2013-01-23T22:20:05.110 に答える