The problem is when I enter a string or a name in the edittext, it cannot be appeared in the textview after i press the button "Send request". I don't know how to fix it.
Please help me!

package com.androidexample.httpgetexample;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class HttpGetAndroidExample extends Activity {

    TextView content;
    EditText userID;

    protected void onCreate(Bundle savedInstanceState) {

        content = (TextView) findViewById(R.id.content);
        userID = (EditText) findViewById(R.id.user);
        Button saveme = (Button) findViewById(R.id.save);

        saveme.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // ALERT MESSAGE

                        "Please wait, connecting to server.", Toast.LENGTH_LONG)
                try {

                    String userIDValue = URLEncoder.encode(userID.getText().toString(), "UTF-8");
                    // HttpClient Client = new DefaultHttpClient();
                    String URL = ""
                            + userIDValue;

                    new HttpAsyncTask().execute(URL);

                } catch (UnsupportedEncodingException ex) {

    public static String GET(String url) {
        InputStream inputStream = null;
        String response = new String(); 
        // result="";
        try {

            if (inputStream != null)
                response = convertInputStreamToString(inputStream);

                response = "Did not work!";

        } catch (Exception e) {
            Log.d("InputStream", e.getLocalizedMessage());

        return response;

    private static String convertInputStreamToString(InputStream inputStream)
            throws IOException {
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(inputStream));
        String line = "";
        // String result = "";
        StringBuilder result = new StringBuilder();
        while ((line = bufferedReader.readLine()) != null)
             result.append(line + "\n");

        return result.toString();


    private class HttpAsyncTask extends AsyncTask<String, Void, String> {
        protected String doInBackground(String... urls) {

            return GET(urls[0]);

        // onPostExecute displays the results of the AsyncTask.
        protected void onPostExecute(String result) {
            Toast.makeText(getBaseContext(), "Received!", Toast.LENGTH_LONG)

            // String type = mainObject.getString("capsuleType");

Edited by thuyson

3 Years
Discussion Span
Last Post by peter_budo

Well either you posted wrong code piece or you did not implemented this yet and trying to trick us in doing your work.

Either way there is no send button and no action associated with it to do what you ask to do

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.