0

I want to be able to get the Source code of a web page (like http://www.google.com) and display it in the Android main activity's text box or a label box... Here is the current code i've written. But it doesn't load the code in the EditText

public class MainActivity extends ActionBarActivity {
public String html = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_main);
    try {
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet("http://www.google.com");
        HttpResponse response = client.execute(request);


        InputStream in = response.getEntity().getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        StringBuilder str = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            str.append(line);
        }
        in.close();
        html = str.toString();
    }
    catch(Exception e){}
    EditText t = (EditText)findViewById(R.id.editText);
    t.setText(html);
}
Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140

1 Answers1

0

I believe EditText should be chained with TextView. Make changes in in layout file similar to this example. You will get the content displayed. I hope it helps. Give it a try. If it doesn't work then let me know. I am sure it will work though.

TRY using t.setText(html, TextView.BufferType.EDITABLE);

Roon13
  • 387
  • 2
  • 23