Im creating AlertDialog box on a class which is not the main Activity and the code below produce error on this. Thanks, I’m new in android app development.
public static void width(){
final CharSequence[] items = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Pick a stroke width");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
String width;
width = (String) items[item];
int th = Integer.parseInt(width);
ScreenTouchEvent.wd = th;
}
});
AlertDialog alert = builder.create();
alert.show();
}
It might be that your function needs to pass in a context.
If that doesn’t help, post your errors.