Reputation: 4433
I am developing an android application in android in which i want to use search option with which i can search particular data item either from web services or from a database ?
Upvotes: 3
Views: 10059
Reputation: 947
you can use the search dialog; see the following link: http://developer.android.com/guide/topics/search/search-dialog.html also: http://mobileorchard.com/android-app-development-implementing-search-activities/
Upvotes: 1
Reputation: 2380
Searching inside your database
SQLLite provides built in functionality to allow for full text searching
From a webservice
As far as searching via a webservice normally you simply send the search terms to the server via your webservice, the server performs the search and you parse the response.
Lucene
Unless what you are REALLY asking about is a search index, where you may have keywords that allows you to quickly index a large database, or a webservice as the data may not be duplicated between the two.
In which case you can use LUCENE
However to get lucene to work with Android you may need to check out the source and remove a few depenencies with RMI.
See the bottom of this page for the solution (only need to remove 2 files and it should compile and work with Android).
How to implement the search dialog box
The developers guide only gives you enough to start implementing the interface to your search dialog box. Read through the example source code (posted below) to see how it fits together into an application.
Android Developers Guide
Example Code
Upvotes: 3
Reputation: 22076
Create an XML file named list_item.xml and save it inside the res/layout/ folder. Edit the file to look like this:
?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:textColor="#000">
</TextView>
main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Country" />
<AutoCompleteTextView android:id="@+id/autocomplete_country"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"/>
</LinearLayout>
java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.autocomplete_country);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.list_item, COUNTRIES);
textView.setAdapter(adapter);
}
Inside the HelloAutoComplete class, add the string array:
static final String[] COUNTRIES = new String[] {
"Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra",};
Upvotes: 3
Reputation: 457
Use edittext with a button or auto complete text view with a button.
Load data from a file or database for the auto complete part. Once you obtain the data, pass it to the web-service call or search your local database for the same.
Hope I got the requirement right and helped you.
Upvotes: 1