prabu
prabu

Reputation: 727

Showing web service's input values in autocompletetextview in android

I am consuming one web service right now.This web service will return some string values if i give proper input values.Here my requirement is, i need to show these input values in AutoCompleteTextView in android.

For example:

Assume my web service is having the input values such as, "AX","AB","B","CC","CX","D" and so on.Here i need to show these input values in AutocompleteTextView in android.

NOTE: I don't want to do hard-code these input values in string format in AutoCompleteTextView, because these input values will be updated day by day.So that there will be no meaning of hard-codding it,is it not?

suggestions please!

thanks for your precious time!..

Upvotes: 0

Views: 1037

Answers (3)

Sarim Javaid Khan
Sarim Javaid Khan

Reputation: 830

This is the way you can get data from your service in the form of string data.

public String getDataFromService()
{
    try {
        HttpClient httpClient=new DefaultHttpClient();
        HttpGet httpGet=new HttpGet(yourserviceURLgoeshere);
        HttpResponse httpResponse=httpClient.execute(httpGet);
        HttpEntity entity = httpResponse.getEntity();
        is=entity.getContent();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return parseExecutedRequest();
}

private String parseExecutedRequest()
{
    try {
        BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
        StringBuilder stringBuilder=new StringBuilder();
        String line=null;

        while((line=bufferedReader.readLine())!=null)
        {
            stringBuilder.append(line+ "\n");
        }

        is.close();
        result=stringBuilder.toString();
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return result;
}

Upvotes: 2

Sanket Kachhela
Sanket Kachhela

Reputation: 10856

in this you to make array if input values and bind it on AutoCompleteTextView. here is the example click this

Upvotes: 0

Sujit
Sujit

Reputation: 10622

You have to create a ArrayList and fill the data you get form web service and set adapter to the AutoCompleteTextView with the ArrayList you have created.

Upvotes: 0

Related Questions