Question

I'm doing some really basics programming at Android Studio. I getting this error on the screen:

Cannot resolve method 'SetPositiveButton'

Is there any import that I'm missing?

Here is my complete code:

package com.kontrol.app;

import android.content.Context;
import android.content.DialogInterface;
import android.preference.DialogPreference;
import android.util.AttributeSet;

public class SS1_Senha extends DialogPreference implements DialogInterface.OnClickListener{

    public SS1_Senha(Context context, AttributeSet attrs) {
        super(context, attrs);
        setPersistent(false);
        setDialogLayoutResource(R.layout.ss1_senha);

        SetPositiveButtonText("OK");
        SetPositiveButtonText("Cancelar")


        setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                //Action after OK

            }
        });


    }
}
Was it helpful?

Solution 2

You can check this answer and do your DialogPreference directly in the XML:

<com.kontrol.app.SS1_Senha
            android:key="@string/the_key"
            android:dialogIcon="@android:drawable/ic_dialog_alert"
            android:title="@string/your_title"
            android:summary="@string/your_summary"
            android:dialogMessage="@string/your_text"
            android:positiveButtonText="Ok"
            android:negativeButtonText="Cancelar"/>

OTHER TIPS

try this please:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
            MainActivity.this);  
        // set title 
        alertDialogBuilder.setTitle("some text");
        alertDialogBuilder.setCancelable(true);
        // set dialog message
        alertDialogBuilder
            .setMessage("some text")
            .setCancelable(true)
            .setPositiveButton( "Yes",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
            try {
               //so some work
            } catch (Exception e) { 
                 //Exception
            }
            }
          })
        .setNegativeButton("No",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
            //do something if you need
                dialog.cancel();
            }
        });

            // create alert dialog
            AlertDialog alertDialog = alertDialogBuilder.create();

            // show it
                alertDialog.show(); 

Make sure you are seeing this method

setPositiveButton(CharSequence text, DialogInterface.OnClickListener listener)

When you start typing .setPos..., select the above option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top