简体   繁体   中英

yes/no dialog in app widget

I need to have a yes/no dialog on the widget that allows for directly pressing yes/no on the widget without starting another dialog. Basically putting a yes and a no button on the widget itself.

While adding a callback with views.setOnClickPendingIntent(R.id.xxx, pendIntent); is no problem, I do not know how to pass a yes/no parameter depending on the user pressing the yes button or the no button.

Each time the user presses yes or no there should be a database update with the answer.

I know I should use a IntentService somehow but I am unclear how to connect that to the widget's two buttons.

ps I would also be thankful for any hint/link to an example widget/app which shows how to best design the layout for such a yes/no dialog on a widget

Many thanks

DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        switch (which){
        case DialogInterface.BUTTON_POSITIVE:
            //Yes button clicked
            break;

        case DialogInterface.BUTTON_NEGATIVE:
            //No button clicked
            break;
        }
    }
};

AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener)
    .setNegativeButton("No", dialogClickListener).show();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM