我有一個問題的ColorPickerDialog http://www.yougli.net/android/a-photoshop-like-color-picker-for-your-android-application/靜態內部類和非靜態的外方法
這ColorPickerDialog在該內靜態類的內部靜態類... 我需要使用「關閉()」或「解僱()」關於ColorPickerDialog關閉它...
我的問題是 public class ColorPickerDialog extends Dialog
的密切()和罷免()方法是在對話框非靜態的。我如何在內部靜態類private static class ColorPickerView extends View
中使用此方法?
編輯... 下面是從代碼中重要的部分..
public class ColorPickerDialog extends Dialog {
public interface OnColorChangedListener {
void colorChanged(String key, int color);
}
private static class ColorPickerView extends View {
@Override
public boolean onTouchEvent(MotionEvent event) {
if (x > 266 && x < 394 && y > 316 && y < 356){
savedDialog();
}
return true;
}
private void savedDialog() {
new AlertDialog.Builder(getContext())
.setTitle("Save to profile?")
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
}).show();
}
}
public ColorPickerDialog(Context context, OnColorChangedListener listener,
String key, int initialColor, int defaultColor) {
super(context);
mListener = listener;
mKey = key;
mInitialColor = initialColor;
mDefaultColor = defaultColor;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OnColorChangedListener l = new OnColorChangedListener() {
public void colorChanged(String key, int color) {
mListener.colorChanged(mKey, color);
dismiss();
}
};
setContentView(new ColorPickerView(getContext(), l, mInitialColor,
mDefaultColor));
setTitle(R.string.pick_a_color);
}
}
,並在這裏,我intatiate的ColorPickerDialog ...
public class LampsFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
OnColorChangedListener listener = new OnColorChangedListener() {
@Override
public void colorChanged(String key, int color) {
}
};
ColorPickerDialog cp = new ColorPickerDialog(getActivity(), listener, key, arg2, arg2);
cp.show();
return false;
}
});
lv.setAdapter(files);
return view;
}
}
我想壓制後關閉ColorPickerDialog來自內部靜態類的AlertDialog上的「YES」。
Jeah內部類不需要爲我的項目靜態 - 我現在將它編輯爲「私人類ColorPickerView ...」 ColorPickerDialog.this.close()也是我的想法。但它不適用於靜態修改器。 謝謝 –