如何从我的实用程序 class 调用 ArrayAdapter 函数?
How do I call an ArrayAdapter function from my Utility class?
嗨,在我的 ArrayAdapter class 中,当我单击按钮时,我正在显示警报对话框。
这个警告对话框和所有相关的编码部分写在我的 "Common utility" class 中,如下所示。
我的要求是当我点击警告对话框 OK
和 CANCEL
按钮时我想在我的适配器中处理点击事件 class
我该怎么做请给我一些建议
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();
}
}
适配器class:-
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");
}
}
只需将 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");
}
})
[...]
}
现在您可以使用 StockBookingExpandableAdapter
作为第二个参数调用 displaySignOutAlertDialog()
。
public void displaySignOutAlertDialog(Context activity, DialogInterface.OnClickListener okHandler, DialogInterface.OnClickListener cancelHandler)
添加对话框按钮处理程序作为函数的参数。而且您还没有在 displaySignOutAlertDialog
上初始化处理程序
嗨,在我的 ArrayAdapter class 中,当我单击按钮时,我正在显示警报对话框。
这个警告对话框和所有相关的编码部分写在我的 "Common utility" class 中,如下所示。
我的要求是当我点击警告对话框 OK
和 CANCEL
按钮时我想在我的适配器中处理点击事件 class
我该怎么做请给我一些建议
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();
}
}
适配器class:-
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");
}
}
只需将 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");
}
})
[...]
}
现在您可以使用 StockBookingExpandableAdapter
作为第二个参数调用 displaySignOutAlertDialog()
。
public void displaySignOutAlertDialog(Context activity, DialogInterface.OnClickListener okHandler, DialogInterface.OnClickListener cancelHandler)
添加对话框按钮处理程序作为函数的参数。而且您还没有在 displaySignOutAlertDialog
上初始化处理程序