Skip to content

Instantly share code, notes, and snippets.

@Nutomic
Created November 26, 2015 21:22
Show Gist options
  • Save Nutomic/b40eb047002715f54e57 to your computer and use it in GitHub Desktop.
Save Nutomic/b40eb047002715f54e57 to your computer and use it in GitHub Desktop.
package com.nutomic.syncthingandroid.preferences;
import android.content.Context;
import android.preference.MultiSelectListPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
public class DynamicListPreference extends MultiSelectListPreference {
public DynamicListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected View onCreateDialogView() {
ListView view = new ListView(getContext());
view.setAdapter(adapter());
setEntries(entries());
setEntryValues(entryValues());
return view;
}
private ListAdapter adapter() {
return new ArrayAdapter<String>(getContext(), android.R.layout.select_dialog_singlechoice);
}
private CharSequence[] entries() {
return new CharSequence[] {"test1", "test2", "test3"};
}
private CharSequence[] entryValues() {
return new CharSequence[] {"test1", "test2", "test3"};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment