1
我試圖連接到網頁,並從頁面獲取一些信息和圖像,並將其置於一個列表視圖中。 現在,我可以得到整個頁面的內容,但我怎樣才能得到一個類或圖像顯示?Android:獲取HTTP頁面並將其刮掉
代碼我現在使用:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
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 android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class Main extends Activity {
/** Called when the activity is first created. */
TextView text;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
text = (TextView) findViewById(R.id.tvText);
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet("http://www.wallbase.cc");
try {
HttpResponse response = client.execute(request);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while((line = rd.readLine()) != null){
text.append(line);
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
啊非常感謝你! – 2012-02-17 17:33:26