我是线程新手,而不是Java中最先进的,但从我的理解,以下应该正确运行,但它没有。我已经尝试过调整内容并阅读线程但无济于事。我试着搜索,但我没有得到任何明确的答案。
代码:
public void getValue(final EditText input1) // 0 all three // 1 ask // 2 buy
{
final Handler handler = new Handler();
final Thread thread = new Thread() {
public void run() {
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://finance.yahoo.com/d/quotes.csv?s="+input1.getText().toString()+"&f=abl1");
HttpResponse response = null;
try {
response = httpClient.execute(httpGet, localContext);
} catch (IOException e) {
e.printStackTrace();
}
final HttpResponse finalResponse = response;
handler.post(new Runnable() {
@Override
public void run() {
try {
textViews[2].setText("Last:Err2");
BufferedReader reader = new BufferedReader(
new InputStreamReader(
finalResponse.getEntity().getContent()
));
updateText( reader.readLine()); // pass data out
} catch (IOException e) {
e.printStackTrace();
}
}
});
} catch (final Exception e) {
e.printStackTrace();
}
}
};
thread.start();
}
答案 0 :(得分:3)