I'm trying to trap event listener on the auto-suggest for my application. i'm populating the list using wiki-suggest : http://en.wikipedia.org/w/api.php?action=opensearch&search=%22bike%22&limit=8&namespace=0&format=json.
I'm getting all the things right but now I want to just click on the item of the list and bring the string to the next activity. I have gone through : http://developer.android.com/reference/android/widget/AutoCompleteTextView.html#setOnItemClickListener(android.widget.AdapterView.OnItemClickListener)
But that is not giving me idea that how can I implement that.
I'm pasting my code here for the auto-suggest populating. Please suggest how to overcome this problem.
@Override
protected String doInBackground(String... key) {
String newText = key[0];
newText = newText.trim();
newText = newText.replace(" ", "+");
try {
HttpClient hClient = new DefaultHttpClient();
HttpGet hGet = new HttpGet(
"http://en.wikipedia.org/w/api.php?action=opensearch&search="
+ newText + "&limit=8&namespace=0&format=json");
ResponseHandler<String> rHandler = new BasicResponseHandler();
data = hClient.execute(hGet, rHandler);
suggest = new ArrayList<String>();
JSONArray jArray = new JSONArray(data);
for (int i = 0; i < jArray.getJSONArray(1).length(); i++) {
String SuggestKey = jArray.getJSONArray(1).getString(i);
suggest.add(SuggestKey);
}
} catch (Exception e) {
Log.w("Error", e.getMessage());
}
runOnUiThread(new Runnable() {
public void run() {
aAdapter = new ArrayAdapter<String>(
getApplicationContext(), R.layout.item, suggest);
autoComplete.setAdapter(aAdapter);
aAdapter.notifyDataSetChanged();
}
});
return null;
}
This is how I get new suggestions from wiki-suggest:
autoComplete = (AutoCompleteTextView) findViewById(R.id.text);
autoComplete.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable editable) {}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {
String newText = s.toString();
new getJson().execute(newText);
}
});