如何从Android中另一个活动上处理警告对话框的正面按钮事件? [英] How to handle event on positive button of alert dialog from another activity in android?

查看:151
本文介绍了如何从Android中另一个活动上处理警告对话框的正面按钮事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为常见的活动我共同的警告对话框说commonActivity()。在我的第二个活动myActivity(),我有一个方法myMethod1()在我第三次活动我有一个方法myMethod2(),我需要在警告对话框的积极按钮的点击呼叫。是否可以使用常见的警告对话框在我所有的活动和积极的点击按钮,消防活动的各个方法?

I have my common alert dialog in a common activity named say commonActivity(). In my 2nd activity myActivity(), I have a method myMethod1() and in my 3rd activity I have a method as myMethod2(), which I need to call on the click of the positive button of the alert dialog. Is it possible to use the common alert dialog in all my activities and on the click of the positive button, fire respective methods of the activities?

推荐答案

请一个接口在commonActivity(例如:onPosClick与方法的onClick()),并在该活动中,你应该声明一个变量公共静态onPosClick MI:
然后在code

Make a Interface in commonActivity( ex: onPosClick with method onClick()) and in this Activity you should declare a variable public static onPosClick mI; then in your code

    dialog.setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int id) {
            mI.onClick();
  }
});

最后在其他活动,你Impliment commonActivity的界面,也许喜欢这里

the last in an other Activity you Impliment the Interface of commonActivity, maybe like here

onCreate(){
  ....
  commonActivity.mI = new onPosClick (){
      @Override
      void onClick(){
      //do something
      }
  }
}

这篇关于如何从Android中另一个活动上处理警告对话框的正面按钮事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆