SearchView with OneClick to enter text - android

In the android default search view, 2 clicks are required to input text for search as the first click is used to expand the editText view and another click is to set focus.
It seems to be q redundant and i want to reduce the process to one click only. Is there any methods to do this?

You can change this behavior by calling
setIconifiedByDefault(false)
on your searchView. Setting it to false will show the whole field.
Documentation here.

The two clicks happen if we put the searchView inside a ListView as the searchView lost focus after that. I suspect searchView behave a similar property with editText view in listView.
With reference to
Edit Text in ListActivity ListView loses focus when keyboard comes up
and add the following codes in searchView xml
android:focusable="true"
android:focusableInTouchMode="true"
would get back the normal behavior of the searchView. Hope this will be useful to other people in the future.

Related

Prevent losing focus on EditText when clicking on a button in Android

I'm writing a custom EditText that will have functionalities to bold/italic/underline/lists .... for Android
It's working so far so good but I've a problem that when a user clicking on a Button (for styling bold/italic...), the user will lose focus on the EditText.
Anyone has any ideas how to prevent the button taking focus from the EditText?
Thanks :)
The easiest thing to do would be to have the onClickListener of those buttons refocus the edit text as their last instruction.
You can also try putting focusable=false (and focusableInTouchMode=false) on the buttons. That may work, I'm not sure if focus is removed from the edit text when the screen is touched or when another item receives focus, which is subtly but important difference here. It would also slightly change any drawables on the button that use focused state.

Default text in the serach bar with AutoCompleteTextView

I'm using the AutoCompleteTextView to allow users to search a from a list of countries. I want to have some default text preloaded in the search bar before the user clicks on it, such as "Search" or "Find Nearest Country". Is it possible to do this? If so how?
Right now, the app opens directly into the search box with the keyboard pulled up. Rather, I want the users to click on the bar before searching.
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
A TextView's hint seems to be exactly what you need. See android:hint for the XML attribute or setHint() for the corresponding Java method.
To prevent the keyboard from popping as soon as your activity is entered, you should set the android:windowSoftInputMode attribute in the activity declaration to stateHidden.

SearchView or EditText is better for search bar function?

I wanted to know whether using the SearchView widgit or the EditText widgit with a Button widgit was a better implementation of a search bar I wanted to create (a search bar meaning you type in a word and u click go and it'll take you to some sort of result).
Its depends on your requirement of your database is huge that the hint results cant be displayed in single screen then better to use edit-text with a go button for search.if you have limited data in list-view or something you can use edit search box.

Tailoring AutoCompleteTextView to fit my needs?

What I want
A simple EditText. User should be able to enter text at any point of time.
onClick of this EditText, a popup should appear anchored to the EditText.
onClick of this EditText, if popup is already being shown, then dismiss the popup.
This popup will contain a list of items (that i decide and no filtering) on clicking of which the EditText will be filled with the clicked item.
When I start typing, the popup should go away.
I should be able to set the animation of the drop down list.
What were my options
Obviously, AutoCompleteTextView. Worked great after customizing AutoCompleteTextView. But there were two problems?
I was able to accomplish points 1, 2, 4 and 5. How do I get around this number 3 and number 5?
Since nothing worked...
I thought I can just put a edit text and show a popup window. :)
But that fails utterly...
I just tried to do the simple way. I added a EditText. And then I created a class of PopupWindow and inflated a listview in it. Then I anchored it to my EditText. Now the problem starts again -
I click on the EditText. The popup appears. Takes all the focus and the keyboard goes away. Definitely not what I want. So i made the popup window not focusable.
And now I click on the EditText, the popup appears. Doesn't take the focus. So keyboard stays to take input. Just perfect like I want. But when I click a list item in the ListView, it doesn't do anything. Why? It is not focusable!
So what do i do now? Which way do I go?
For 3. you can create an onFocusChange listener, or and onClickListener and explicitly call _autoCompleteView.dismissDropDown();. You can use isPopupShowing() to see if it is already showing and manually dismiss it in that case.
For 5. you just do the same thing but you do _autoCompleteView.registerDataSetObserver and put that logic in the onChanged() event or possibly in the addTextChangedListeneron your autoCompleteTextView.
I am not entirely sure if this is the functionality you were looking for but this thread is almost a year old now so maybe it will be helpful for someone in the future.

Android Floating EditBox

I have an OptionMenu which has single option in it named "Search". When the search option is clicked, it should dynamically add a EditText at the top of Activity window like it has in WebView (browser address bar) so users could search something in my application.
After there would be EditBox, one can write inside it. I also want to have some OnTextChanged like event of that EditBox so do you think it's also available with that View?
I made it myself. I added an EditText on the screen with setting as hidden and on button click made it visible. It worked like a charm.

Categories

Resources