Reputation: 159
hello iam a novice to android app development i recently leant how to implement list activity i have a application which shows the all states of USA
now i have to add a simple search facility to this app when required state name is typed it shud display the state name and print a msg when it doesn't find suitable name!!
package shashi.android.Statelist;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
public class Statelist extends ListActivity {
String[] listofstates = { "Alabama: AL",
"Alaska: AK",
"Arizona: AZ",
"Arkansas: AR",
"California: CA",
"Colorado: CO",
"Connecticut: CT",
"Delaware: DE",
"Florida: FL",
"Georgia: GA",
"Hawaii: HI",
"Idaho: ID",
"Illinois: IL",
"Indiana: IN",
"Iowa: IA",
"Kansas: KS",
"Kentucky: KY",
"Louisiana: LA",
"Maine: ME",
"Maryland: MD",
"Massachusetts: MA",
"Michigan: MI",
"Minnesota: MN",
"Mississippi: MS",
"Missouri: MO",
"Montana: MT",
"Nebraska: NE",
"Nevada: NV",
"New Hampshire: NH",
"New Jersey: NJ",
"New Mexico: NM",
"New York: NY",
"North Carolina: NC",
"North Dakota: ND",
"Ohio: OH",
"Oklahoma: OK",
"Oregon: OR",
"Pennsylvania: PA",
"Rhode Island: RI",
"South Carolina: SC",
"South Dakota: SD",
"Tennessee: TN",
"Texas: TX",
"Utah: UT",
"Vermont: VT",
"Virginia: VA",
"Washington: WA",
"West Virginia: WV",
"Wisconsin: WI",
"Wyoming: WY"
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, listofstates));
}
}
the search i need. e.g.: to retrieve the typed text and return my search response
So, basically i need just the design, not it's functionality.
Can someone tell me if i can use this bar only for my personal data, not a general search from internet or the hole phone, and i would appreciate link for a simple and clear tutorial, because i couldn't found anything concrete till now.
like only the result for finding the typed text or else printing the "result not found" msg
thanks in advance!!
Upvotes: 0
Views: 3580
Reputation: 87533
Take a look at AutoCompleteTextView
:
http://developer.android.com/reference/android/widget/AutoCompleteTextView.html
Tutorial:
http://developer.android.com/resources/tutorials/views/hello-autocomplete.html
Auto Complete
To create a text entry widget that provides auto-complete suggestions, use the AutoCompleteTextView widget. Suggestions are received from a collection of strings associated with the widget through an ArrayAdapter.
In this tutorial, you will create a AutoCompleteTextView widget that provides suggestions for a country name.
Upvotes: 3