public class Fragment_Layers extends Fragment implements Dialog_SpinnerSelect.ResultListener {
......
void openDialog() {
Dialog_SpinnerSelect dialog = new Dialog_SpinnerSelect(getActivity());
dialog.show();
}
@Override
public void onSpinnerSelectResult(Integer result) {
//todo
}
}
public class Dialog_SpinnerSelect {
private Context context;
public Dialog_SpinnerSelect(Context context) {
this.context = context;
builder = new AlertDialog.Builder(context);
}
public void show() {
......
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int arg1) {
((ResultListener) context).onSpinnerSelectResult(keys[selecteditemid]);
}
});
.......
dialog.show();
}
public interface ResultListener {
void onSpinnerSelectResult(Integer result);
}
}
Dialog_SpinnerSelect dialog = new Dialog_SpinnerSelect(getActivity());
наDialog_SpinnerSelect dialog = new Dialog_SpinnerSelect(this);
;private Context context;
public Dialog_SpinnerSelect(Context context) {
this.context = context;
builder = new AlertDialog.Builder(context);
}
наprivate Fragment_Layers fragment;
public Dialog_SpinnerSelect(Fragment_Layers fragment) {
this.fragment = fragment;
builder = new AlertDialog.Builder(fragment.getActivity());
}
;public void onClick(DialogInterface dialog, int arg1) {
((ResultListener) context).onSpinnerSelectResult(keys[selecteditemid]);
}
наpublic void onClick(DialogInterface dialog, int arg1) {
((ResultListener) fragment).onSpinnerSelectResult(keys[selecteditemid]);
}