我有一个 ColorPickerDialog 的问题http://www.yougli.net/android/a-photoshop-like-color-picker-for-your-android-application/
这个 ColorPickerDialog 有一个内部静态类...在这个内部静态类中,我需要在 ColorPickerDialog 上使用“close()”或“dismiss()”来关闭它...
我的问题是
public class ColorPickerDialog extends Dialog
close() 和dismiss() 方法在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);
}
}
在这里我开始使用 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;
}
}
我想在内部静态类的 AlertDialog 上按“YES”后关闭 ColorPickerDialog。