打开AlertDialog时如何知道按下的按钮?

时间:2017-04-09 14:06:57

标签: java android

我有这个:

  public void showDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(updatedActivity.this);
    builder.setTitle("Choose the currency you would like to exchange.");

    //list of items
    String[] items = getResources().getStringArray(R.array.countries_array);
    builder.setSingleChoiceItems(items, 0,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {

                }
            });

    String positiveText = getString(android.R.string.ok);
    builder.setPositiveButton(positiveText,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    //So here i wanna a code like : If pressbutton = buttonto, then buttonto.setText(selecteditem..)
                }
            });


    String negativeText = getString(android.R.string.cancel);
    builder.setNegativeButton(negativeText,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // negative button logic
                }
            });

    AlertDialog dialog = builder.create();
    // display dialog
    dialog.show();
}

在点击事件中,我想知道按下了哪个按钮,例如,如果按钮,则按钮,然后按钮设置(所选项目)

那怎么做 感谢

0 个答案:

没有答案