Adding a search bar
Post a Reply
|Oldest Newest Rating|
· October 17, 2015
No I don't know how to debug yet, I just started to learn how to program. How do you know when you're using the right widget?
· October 17, 2015
It has only been 3 days since my reply and I have found 3 more ways to get halt my program.
1. Today I was following and example in a book and made a style that wasn't compatible with my activity. (Wouldn't even launch)
2. Yesterday I forgot to include the required parameters in an override. (died when I clicked a button)
3. I passed the wrong type of value.
The answer to your question about the right widget has to do with findViewById()
findViewById looks for the id you defined with the Android:id tag in your xml.
Here is my suggestion.
Reply with more information:
1. Include a screen dump of the error or just copy and paste the first few lines when the log file turns Red.
you can use the add image icon to paste the screen dump.
2. You say it worked before you added the search code so include your code using the Add Code icon.
· October 26, 2015
Sorry for the late response! Here are screen shots of the code.
· October 27, 2015
Thanks for the Screenshots.
First let me say that I haven't used the searchview widget yet, so I read about it on Android.com.
The searchdialog is used in the Action Bar and the searchview is used in your layout.
There is more you will have to to create a android.intent.action.SEARCH" but you are not there yet right?
You just want your app to not stop working.
So here are somethings I noticed from your screenshots.
1. your app extends AppcompatActivity - ok
2. your manifest declares the app theme with NoActionBar. - but
your main activity tries to implement an ActionBar - this seams contradictory to me. Why not just declare your theme to use an ActionBar? or do you want to use the ActionDialog which goes in the ActionBar?
3. you have the same Toast for all your options in the menu listener.
4. your reference to your searchview finds the id declared in your homelayout.
My suggestion if you want to play with the searchview widget is to keep it simple.
Drop switch from your menu options you don't have anything there unless your menu.xml file has them, which you didn't include in your screen shots. This is probably what is killing your app.
Just use an ActionBar theme if you want an ActionBar.
I hope this helps
P.S. I found this during my searching http://javapapers.com/android/android-searchview-action-bar-tutorial/
· October 10, 2015
I have had this error many times.
It is usually a logic error.
The code compiles but then tries to do something that "doesn't compute".
· October 12, 2015
Is there a way to fix this to get the app to work?
· October 14, 2015
Do you know how to use the debugger?
You can set a breakpoint before the new code.
Or you can try the old fashion way of commenting out the code you added and selectively adding back a few lines after each run.
Pay particular attention to your references. Ex. Did you ref the widget you meant to? If you try to run a method on the wrong type of widget, that won't work.
Java / Android Development
Very popular language used to create desktop applications, website applets, and Android apps.
|Bucky Roberts Administrator|