diff --git a/MyTracks/res/xml/preferences.xml b/MyTracks/res/xml/preferences.xml index 25363a466..5c371eec4 100644 --- a/MyTracks/res/xml/preferences.xml +++ b/MyTracks/res/xml/preferences.xml @@ -152,7 +152,7 @@ limitations under the License. android:summaryOff="@string/settings_timestamp_track_name_summary_off" android:defaultValue="true" /> - + * This preference will store a string into the SharedPreferences. + * + * @author Rimas Trumpa (with Matt Levan) + */ +public class AutoCompleteTextPreference extends EditTextPreference { + + private static AutoCompleteTextView mEditText = null; + + public AutoCompleteTextPreference(Context context, AttributeSet attrs) { + super(context, attrs); + mEditText = new AutoCompleteTextView(context, attrs); + mEditText.setThreshold(0); + + // Gets autocomplete values for 'Default Activity' preference + if (getKey().equals(context.getString(R.string.default_category_key))) { + ArrayAdapter adapter = ArrayAdapter.createFromResource(context, + R.array.activity_types, android.R.layout.simple_dropdown_item_1line); + mEditText.setAdapter(adapter); + } + } + + @Override + protected void onBindDialogView(View view) { + AutoCompleteTextView editText = mEditText; + editText.setText(getText()); + + ViewParent oldParent = editText.getParent(); + if (oldParent != view) { + if (oldParent != null) { + ((ViewGroup) oldParent).removeView(editText); + } + onAddEditTextToDialogView(view, editText); + } + } + + @Override + protected void onDialogClosed(boolean positiveResult) { + if (positiveResult) { + String value = mEditText.getText().toString(); + if (callChangeListener(value)) { + setText(value); + } + } + } +}