Android add custom search bar in application - android

I want to implement search bar in my application which will filter list view depending on letters entered in edit text. Here is what I have actually like a design
So I want to filter the elements by title so I guess I have to change the sqlite statement, because I'm populating the listview from database.
And I have two question :
1.Which is the best way to implement custom search bar : add textwatcher to an edit text and change the sqlite statement everytime user enter letter or ?
2.How to sort in sqlite depending on letters entered from user. If user press A I want to show all items which have that letter no matter if it's in the beginning or in the end.

So the things to achieve this are very simple, no matter what kind of Adapter are you using. First you need to create TextWatcher and add it to your Edit Text. Than in your onAfterTextChanged() you can create your new SQL statement like :
String sql = "SELECT title FROM cards WHERE title LIKE '%"+someString+"%'"
//where someString is `Charsequence` which you get in your onAfterTextChanged()
Before getting your data again if you are using ArrayList or any other kind of Lists for storing your data you have to clear them, so you can get the new data. And than you can simply call adapter.notifySetDataChanged(). And it should work. At least this is the way how I'm doing this. Maybe it's not the best way, but it's working.

What is the size of your database? if it is not a BIG one then i think the simple SQL should work for you:
SELECT Column1, Column2
FROM myTable
WHERE myColumn LIKE 'somecharacter%'
You can call to DB while the user is typing or can use some other logic like when the user press a specific button.

Related

Can you use a search widget to search for text in android:text="______" fields?

I'm building an app with linear and relative layouts to create lists. I want to have a search function to search through text fields and return the results with "links" to the pages it pulls the results from.
I don't know if I am explaining this well enough, but that's what I need help with. I can find all sorts of search help but it all seems to revert back to ListView's.
You should aim to create your "lists" from some form of data-store. Usually a database, see SQLite Databases in Android. You should then use the query language to return only fields that match your search term e.g. "SELECT * FROM people WHERE name = 'Adam'".
To directly answer your question, the searching of text fields (EditText's or TextViews) is not possible to do automatically and you would need to hard code the search for each individual one.

Android Searchview with autocomplete style

What's the best approach in Android to get a searchview with autosearch results styled like this example from the Uber app? I especially like how the results are displayed directly on the screen and not with a dropdown look.
I was thinking possibly getting the query of a search and add the results on the screen dynamically as buttons but there must be a simple way to achieve the style and functionality they have here. Open to any suggestions.
I just took a look at the Android's Uber app, and there they have an EditText on the top with a ListView below that. Whenever the user types in anything in the EditText, the query is made to the server to get the data from it, and the results are displayed in the ListView below.
You should make the query to the server in afterTextChanged() method of the EditText TextWatcher. Also, make sure when the user is typing in continuously, cancel the previous request and only the latest char change query string should go in the request.

Android: How to put each tuple returned from a SQL database as text on a button?

so I am making this app which currently connects to an external SQL database with a list of item names (I use php and json for this), and it displays these names as a textView. I followed this tutorial to learn this:
http://www.youtube.com/watch?v=4Soj22OMc98
However, what I really want to do is have the app have a button for EACH of the item names. Is there a way to make my app such that for each item name it pulls from the database, it creates a button, with the item's name as the text on that button?
This is very do-able. For each item name retrieved from your database, you need to programatically create a button and set the text attribute to the name.
Button b = new Button();
b.setText(insertNameHere);
Of course you also need to set the position of these buttons as well. This resource gives a good tutorial for creating buttons in this way: Tutorial

Building a simple android quote app

New to android development. I recently finished the lynda.com tutorials, but want to get more involved. I was thinking about doing an app that shows various quotes from movies, but am in need of some guidance. I just want it to have one activity and am going to have a next and previous buttons at the top. How would I create the app that shows quotes in a randomized order and keep the quotes on the same screen?
Thanks for any and all help!
Create an SQL Database and store your strings in the table and display it using list view.
http://www.androidhive.info/2011/11/android-sqlite-database-tutorial/ - tutorial for database.
Your request is essentially just a basic layout question: Create a basic view, lay it out with a text field and two buttons. Create either an array list of strings or an SQLite database (as detailed by user3245033). You will then need to add listeners to both buttons (http://developer.android.com/reference/android/widget/Button.html). The next button should generate a random number that becomes an index into the list or database storing your quotes, the back button should store the previous index value (so that you can go back to the same quote as opposed to a random quote). When you're retrieved your quote, set the text field to that string.
There are many basic examples that demonstrate this type of work. mybringback on YouTube particularly amazing:
http://www.youtube.com/playlist?list=PLB03EA9545DD188C3

How do you save a (user-created) dynamic Layout in Android?

I have a button on my home screen that will add an edit text field every time it is pushed (I limited it to 20 for best practice). It is basically a small budgeting app. I want the user to fill in an X amount of dollars in one of the fields. Then, when they are ready, to come back to the app another time and that created EditText is still there filled with the value. I know how to utilize SharedPerfrences to hold the value. I do not, however, know how to hold that newly created EditText field when the user comes back.
I am acutally going to expand and have a button and a datepicker associated with each EditText field so soon click the button will create three objects, not just one. But I want to get one working first and will apply the principle to the others later. Any suggestions?
Sounds like a good candidate for a SQLite database.
For instance, I use a SQLite database to retain and recall the co-ordinates and types of widgets that the user has arranged within my application.
Note that you don't ever want to be trying to store and recall the actual EditText View object itself. In your database you need to devise your own table format that suits the kind of information you need to store. If you simply need to retain the states of a series of EditText fields then this could be as simple as having a table with just one column that contains a string value on each row. To build your UI up again from that database, you'd loop through and create a new instance of EditText, and set the text of each one from the table.
You would have to use Android Parcelable interface, refer to this to know as of how to implement it, refer to this question which I has asked on StackOverflow, it has a good answer.

Categories

Resources