Android 在textview中查看web文件

Android 在textview中查看web文件,android,androidhttpclient,Android,Androidhttpclient,我希望html文件使用httpClient类在我的文本视图中显示Web上的任何文件。但它只显示了我在android中设置的初始值:text。我无法获得所需的输出 帮帮我 这是代码 activity_mail.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_par

我希望html文件使用httpClient类在我的文本视图中显示Web上的任何文件。但它只显示了我在android中设置的初始值:text。我无法获得所需的输出

帮帮我

这是代码

activity_mail.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
GetMethodEx.java

    package com.vivek.jsonpractice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;

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;



public class GetMethodEx {

    public String getData() throws URISyntaxException, ClientProtocolException, IOException{
        BufferedReader in = null;
        String data = null;
        try{
            HttpClient client = new DefaultHttpClient();
            URI website = new URI("https://www.google.co.in/");
            HttpGet request = new HttpGet();
            request.setURI(website);
            HttpResponse response = client.execute(request);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String l = "";
            String nl = System.getProperty("line.separator");
            while((l=in.readLine()) != null){
                sb.append(l+nl);
            }
            in.close();
            data = sb.toString();
            return data;


        }finally{
            if(in != null){
                try{
                    in.close();
                    return data;
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
    }

您是否尝试记录数据变量?调试或编写日志以打印返回的所有值是的,我这样做了,但返回的字符串变量中没有返回值@斯雷坎特
    package com.vivek.jsonpractice;

import android.os.Bundle;
import android.app.Activity;

import android.widget.TextView;

public class MainActivity extends Activity {
    TextView stuff;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        stuff= (TextView)findViewById(R.id.inData);
        GetMethodEx test = new GetMethodEx();
        String returned;
        try {
            returned = test.getData();
            stuff.setText(returned);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

}
    package com.vivek.jsonpractice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URI;
import java.net.URISyntaxException;

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;



public class GetMethodEx {

    public String getData() throws URISyntaxException, ClientProtocolException, IOException{
        BufferedReader in = null;
        String data = null;
        try{
            HttpClient client = new DefaultHttpClient();
            URI website = new URI("https://www.google.co.in/");
            HttpGet request = new HttpGet();
            request.setURI(website);
            HttpResponse response = client.execute(request);
            in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer sb = new StringBuffer("");
            String l = "";
            String nl = System.getProperty("line.separator");
            while((l=in.readLine()) != null){
                sb.append(l+nl);
            }
            in.close();
            data = sb.toString();
            return data;


        }finally{
            if(in != null){
                try{
                    in.close();
                    return data;
                }catch(Exception e){
                    e.printStackTrace();
                }
            }
        }
    }
    }