I am trying to make a custom preference using aa multi select list that I want to programmatically fill in. I tried to create a custom DialogPreference as seen below and used a AlertDialog builder to create my dialog. The problem is that piecing together different tutorials, I am implementing/overriding onCreateDialogView() which needs to return a View. I am not sure if it is possible to get an AlertDialog.Builder to return a View.
public class notifyPreferances extends DialogPreference {
//Tag used for logcat
String TAG = "notifyPreferances";
//Store values to diplay in mutliselect list
CharSequence[] selections;
//Constructor
notifyPreferances(Context context, AttributeSet attrs, CharSequence[] options) {
super(context, attrs);
setPersistent(false);
selections = options;
}
@Override
protected View onCreateDialogView() {
//Initialize Builer
AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
//Set Dialog Title
builder.setTitle("Lights/Groups")
//Set the items for the list and the onclick actions
builder.setItems(selections, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Log.i(TAG, "Selected Option: " + selections[item]);
}
});
return builder.create();
return super.onCreateDialogView();
}
@Override
protected void onDialogClosed(boolean positiveResult) {
super.onDialogClosed(positiveResult);
}
}
Any thoughts or recommendation on how I can solve this problem be either returning the builder as a view, or a different way to programatically create the Dialog would be greatly appreciated.
Here are the two tutorials I am trying to combine: Concise way of writing new DialogPreference classes? and Android: Select items in a multi-select ListView inside AlertDialog