Reputation: 1
I am creating a library search engine based on android. I want to have an EditText field in my application, where user will put the search text. And upon clicking the search button it should search using the library web page. I want to use the text being put in the EditText field to be used by the web page in the background and want to show the result to the user. Could find a clue. I will be really grateful if you could answer asap.
Thanks. / Hasibur Rahman
Upvotes: 0
Views: 1193
Reputation: 874
The quick answer is to look here: http://developer.android.com/guide/index.html and run through some of the sample/tutorials to get a hang of the Android SDK.
You can use the following sample to get the text from the edit box:
@Override
public void onCreate(Bundle savedInstanceState) {
// Get the appropriate EditText from your layout
final EditText myEditText = (EditText) findViewById(R.id.insert_your_edit_text_id_here);
// Get the value from the edit text
String somestring = myEditText.getText().toString().trim();
// Check the value and call the method
if(somestring != null && somestring != "")
{
callthewebservice(somestring);
}
}
Upvotes: 0
Reputation: 36846
The text value of an EditText control can be accessed via EditText.getText().toString()
You'll need to grab that value, most likely URL encode it, and then pass it to the search URL of the library web page.
Just as an example...
EditText searchBox = (EditText) findViewById(R.id.searchBox);
String searchTerm = searchBox.getText().toString().trim();
String query = URLEncoder.encode(searchTerm, "utf-8");
String url = "http://stackoverflow.com/search?q=" + query;
Upvotes: 3