I am making an android app. There is a problem coming with autocomplete. Autocomplete is working when i connect autocomplete with a variable like this
String[] languages = { "C","C++","Java","C#","PHP","JavaScript","jQuery","AJAX","JSON" };
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.select_dialog_singlechoice, languages);
//Find TextView control
AutoCompleteTextView acTextView = (AutoCompleteTextView) findViewById(R.id.languages);
//Set the number of characters the user must type before the drop down list is shown
acTextView.setThreshold(1);
//Set the adapter
acTextView.setAdapter(adapter);
But i want too connect it to my web page which generates JSON i tried to connect it with my web page but its not working.
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://example.com/test.php");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
Log.e("Pass 1", "connection success ");
}
catch(Exception e)
{
Log.e("Fail 1", e.toString());
}
try
{
BufferedReader br=new BufferedReader(new InputStreamReader(is,"iso-8859-8"),8);
StringBuilder sb=new StringBuilder();
while((line=br.readLine())!=null)
{
sb.append(line+"\n");
}
is.close();
result=sb.toString();
Log.e("Pass 2", "Success");
}
catch(Exception e)
{
Log.e("Fail 2", e.toString());
}
try
{
JSONArray ja=new JSONArray(result);
JSONObject jo=null;
String[] str=new String[ja.length()];
for(int i=0;i<ja.length();i++)
{
jo=ja.getJSONObject(i);
str[i]=jo.getString("name");
}
MultiAutoCompleteTextView auto=(MultiAutoCompleteTextView) findViewById(R.id.names);
auto.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
ArrayAdapter<String> adp= new ArrayAdapter<String>(getBaseContext(),
android.R.layout.simple_dropdown_item_1line,str);
adp.setDropDownViewResource(android.R.layout.simple_expandable_list_item_1);
auto.setThreshold(1);
auto.setAdapter(adp);
}
catch(Exception e)
{
Log.e("Fail 2", e.toString());
}
}
I just wanna connect my auto complete with my webpage and retrieve name string when search. I also added Internet permissions to my Android Manifest.