Custom android preference type loses focus when typing
Posted
by
Brian
on Stack Overflow
See other posts from Stack Overflow
or by Brian
Published on 2010-12-21T11:35:16Z
Indexed on
2011/02/23
7:25 UTC
Read the original article
Hit count: 224
android
I created a simple preference class that shows an AutoCompleteTextView control and it displays properly but when i focus on the AutoCompleteTextView and start typing it brings up the keyboard but then immediately loses focus on the control.
Any idea why this loses focus?
Here's what i did to create the view. the inflated layout is just a basic linear layout with a title textview in it.
I could change it to a dialog preference instead I guess but it'd be smoother if it could be part of the base view.
@Override
protected View onCreateView(ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.base_preference, null);
if (mHint != null) {
TextView hintView = (TextView) layout.findViewById(R.id.PreferenceHintTextView);
hintView.setText(mHint);
}
TextView titleView = (TextView) layout.findViewById(R.id.PreferenceTitleTextView);
titleView.setText(getTitle());
AutoCompleteTextView inputView = new AutoCompleteTextView(getContext());
inputView.setGravity(Gravity.FILL_HORIZONTAL);
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(),
R.layout.auto_complete_text_list_item,
getEntries());
inputView.setAdapter(adapter);
inputView.setThreshold(1);
inputView.setOnItemSelectedListener(this);
layout.addView(inputView);
return layout;
}
© Stack Overflow or respective owner