English 中文(简体)
多个OK/Cancel dialogs,如何在Click(Click)中说明哪些是方言?
原标题:Multiple OK/Cancel dialogs, how to tell, in onClick(), which dialog?

我创建了一个通用的奥卡西拉多语种,在我全心全意通过静态的方法被轻易援引:

  static public void Prompt(String title, String message) {
    OkCancelDialog okcancelDialog = new OkCancelDialog();
    okcancelDialog.showAlert(title, message);     
  }

出于各种原因,我需要凯克听众参加这项活动,因此,我的活动是:

  public void onClick(DialogInterface v, int buttonId) {
    if (buttonId == DialogInterface.BUTTON_POSITIVE) { // OK button
         // do the OK thing
    }
    else if (buttonId == DialogInterface.BUTTON_NEGATIVE) { // CANCEL button
         // do the Cancel thing
    }
    else {
      // should never happen
    }
  }

这一工作很出色,只用了一张方言,但现在我想加上另一个由同一活动处理的K/Cancel方言。 就我所知,只有一份<代码>onClick(>)可以界定这项活动,因此我无法确定如何执行。

任何建议或建议?

最佳回答

......

public class MyActivity extends Activity
    implements DialogInterface.OnClickListener {

    // Declare dialogs as Activity members
    AlertDialog dialogX = null;
    AlertDialog dialogY = null;

    ...

    @Override
    public void onClick(DialogInterface dialog, int which) {

        if (dialogX != null) {
            if (dialogX.equals(dialog)) {
                // Process result for dialogX
            }
        }

        if (dialogY != null) {
            if (dialogY.equals(dialog)) {
                // Process result for dialogY
            }
        }
    }
}

http://www.ohchr.org。 这就是我如何创建我的<条码>。 2. 通知/编码......

private void createGuideViewChooserDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Select Guide View")
        .setSingleChoiceItems(guideViewChooserDialogItems, currentGuideView, this)
        .setPositiveButton("OK", this)
        .setNegativeButton("Cancel", this);
    guideViewChooserDialog = builder.create();
    guideViewChooserDialog.show();
}
问题回答

你有两个选择。 (1) 你可以把OnClickListener放在方言上。 2) 你可以说,根据当时传到的DialogInterface,是哪个方言。





相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签