Android Tutorial Using standard Android search dialog with Basic4Android

bluedude

Well-Known Member
Licensed User
Longtime User
Keyboard not hiding when clicking in main activity

Hi,

When I enable the search and then click somewhere in the activity the search dialog hides but the keyboard stays open. Tried to find where I can trigger search dialog closing but it cannot find it.

Any suggestions?
 

airblaster

Active Member
Licensed User
Longtime User
Hi Corwin 42,

great tutorial, thanks!
Just one question that comes to mind: Why is it not possible to use auto suggest and search history without a library?
 

corwin42

Expert
Licensed User
Longtime User
As I remember correctly you need to implement a (quite simple) content provider for this.

Unfortunately I never really used the search feature and so I never tried more advanced things with it.
 

walterf25

Expert
Licensed User
Longtime User
Problem launching on a second activity

Hi all, i was wondering if anyone has came across this issue, i have 3 different activities, i can make this work on the main activity, the searchbox pops us and i can type anything and search for anything, but i'm trying to do the same on the second activity named "Activity2" i basically copied everything just as in the main activity and i get no errors, but i don't see the searchbox pop up, does anyone have any idea why this would be, it doesn't make sense to me, this is my code to get this going.

B4X:
Dim ref As Reflector
   ref.Target = ref.GetActivity
   Log(ref.Target)
   ref.RunPublicmethod("onSearchRequested", Null, Null)

I also have the Result trasnsparent activity, and as i mentioned above this works just fine on the main activity, but why wouldn't it work on a second activity?

:sign0163::sign0163::sign0163::sign0163:
:BangHead:
 

walterf25

Expert
Licensed User
Longtime User
Problem launching on a second activity

Never mind i got it, you just need to add a second line like this with the name of the activity you want to start it from like this

AddActivityText(Activity2, <meta-data android:name="android.app.default_searchable"
android:value=".result" />)

thanks All
 

jalle007

Active Member
Licensed User
Longtime User
Is there a way to search android settings
using this approach ?
you know there are a lot of settings that are hard to remember where they are located. and instead of looking into the menu,
best would be to make it searchable.

you know even windows 7 has search settings functionality :icon_clap:
 

corwin42

Expert
Licensed User
Longtime User
No (or yes?), the standard Android search dialog does nothing other than requesting a search string from the user and starts an activity and gives this search string as a parameter.

What you do with the search string and doing the actual search is part of the application.

So the answer is:

No - This approach will not help you in implementing a setting search feature

Yes - You can use the search dialog to implement a setting search feature by yourself. But the handling of the search dialog (which is explained in this tutorial) is the smallest part of such a feature.
 

spyboy79

New Member
Licensed User
Longtime User
Good morning,
I'm testing the search dialog with provided example on emulator and i9000 but I have this error:


main_button1_click (B4A line: 42)


ref.Target = ref.GetActivity
java.lang.NoSuchFieldError: anywheresoftware.b4a.BA.activityBA


at anywheresoftware.b4a.agraham.reflection.Reflection.GetActivity(Reflection.java:638)
at de.amberhome.searchexample.main._button1_click(main.java:306)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:155)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:151)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:59)
at android.view.View.performClick(View.java:4204)
at android.view.View$PerformClick.run(View.java:17355)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)


at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **

what can it be?
 

Taha

Member
Licensed User
Longtime User
Thanks for great tutorial! Is there any event like "TextChanged" in the search textbox?
 

corwin42

Expert
Licensed User
Longtime User
Thanks for great tutorial! Is there any event like "TextChanged" in the search textbox?

No, unfortunately not.
 

focus330

Member
Licensed User
Longtime User
I'm using the android standard search. Everythink works well except when user exit from search without searching anythink. In this case the caller activity doesn't intercept that search is finished and Activity_Resume in not affected. Then I tried to use Activity_WindowFocusChanged. It works fine but I have many problems in debug mode. Then the question: Is there another way to capture exit from search when user doesn't search anything ?

Thanks.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…