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

时间:2016-04-23 07:05:09

标签: android android-alertdialog android-adapter

当我点击按钮时,在我的ArrayAdapter类中,我显示了“警告”对话框。

此警报对话框和所有相关的编码部分都写在我的" Common utility"如下所示。

我的要求是当我点击提醒对话框OKCANCEL按钮时,我想处理我的适配器类中的点击事件

我怎么能这样做,请建议我一些

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");
    }
}

2 个答案:

答案 0 :(得分:1)

只需将CommonUtils.BackGroundDialogeCall传递给displaySignOutAlertDialog(),然后拨打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");
              }
           })
    [...]
}

现在,您可以使用displaySignOutAlertDialog()作为第二个参数调用StockBookingExpandableAdapter

答案 1 :(得分:0)

cat test.z* > hugetest.zip
unzip hugetest.zip

添加对话框按钮处理程序作为函数的参数。而且你没有在displaySignOutAlertDialog

上初始化处理程序