简体   繁体   English

如何从我的 Utility 类调用 ArrayAdapter 函数?

[英]How do I call an ArrayAdapter function from my Utility class?

Hi in my ArrayAdapter class when I click on button I'm showing Alert dialog box.嗨,在我的 ArrayAdapter 类中,当我单击按钮时,我正在显示警报对话框。

This alert dialog box and all related coding part is written in my "Common utility" class as like below.这个警报对话框和所有相关的编码部分都写在我的“通用实用程序”类中,如下所示。

My requirement is when I tap on alert dialogue box OK and CANCEL buttons I want to handle that click events in my Adapter class我的要求是当我点击警告对话框OKCANCEL按钮时,我想在我的 Adapter 类中处理该点击事件

how can I do this please suggest me some one我该怎么做,请给我推荐一些

CommonUtilities:- CommonUtilities:-

public class CommonUtils  {

   BackGroundDialogeCall backGroundDialogeCall;

   public interface BackGroundDialogeCall {

      void doDialogueExecute(String result);
   }
//Adding Dialoge box:-

/**
 *
 */

public void displaySignOutAlertDialog(Context activity) {

   new AlertDialog.Builder(activity)
         .setTitle("Alert")
         .setMessage(activity.getResources().getString(R.string.release_alert_title))
         .setPositiveButton(android.R.string.yes,
               new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog,
                                 int which) {

                     dialog.dismiss();
                  }
               })
         .setNegativeButton(android.R.string.no,
               new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog,
                                 int which) {
                     dialog.dismiss();
                  }
               }).show();
   }
}

Adapterclass:-适配器类:-

public class StockBookingExpandableAdapter extends BaseExpandableListAdapter implements CommonUtils.BackGroundDialogeCall {

    private Context context;

    public StockBookingExpandableAdapter(Context context, ArrayList<StockBookingHeaderBean> stockbookingList) {

        this.context = context;
    }
@Override
public void doDialogueExecute(String result) {

    if (result.equals("yes")){
        Log.d("=====>", "111");
    }else{
        Log.d("=====>", "222");
    }
}

Just pass a CommonUtils.BackGroundDialogeCall to displaySignOutAlertDialog() and call the doDialogueExecute() in there.只需通过一个CommonUtils.BackGroundDialogeCalldisplaySignOutAlertDialog()并调用doDialogueExecute()在那里。

public void displaySignOutAlertDialog(Context activity,
                                final BackGroundDialogeCall call) {
    [...]
         .setPositiveButton(android.R.string.yes,
              new DialogInterface.OnClickListener() {
                  public void onClick(DialogInterface dialog,
                                 int which) {
                 dialog.dismiss();
                 call.doDialogueExecute("yes");
              }
           })
    [...]
}

Now you could just call displaySignOutAlertDialog() with StockBookingExpandableAdapter as second parameter.现在您可以使用StockBookingExpandableAdapter作为第二个参数调用displaySignOutAlertDialog()

public void displaySignOutAlertDialog(Context activity, DialogInterface.OnClickListener okHandler, DialogInterface.OnClickListener cancelHandler)

Add dialog button handler as your function's parameters.添加对话框按钮处理程序作为函数的参数。 And you have not initialize handler on displaySignOutAlertDialog而且您还没有在 displaySignOutAlertDialog 上初始化处理程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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