在Asynctask类中调用另一个类的view,但是没成功,请帮忙。
异步任务:
private class parseSite extends AsyncTask<String, Void, List<Integer>> {
protected List<Integer> doInBackground(String... arg) {
List<Integer> output = new ArrayList<Integer>();
try {
htmlHelper hh = new htmlHelper(new URL(arg[0]));
output = hh.htmlHelper(arg[0]);
} catch (Exception e) {
System.out.println("Error");
}
return output;
}
protected void onPostExecute(List<Integer> exe) {
graph salesView = new graph();
View chartView = salesView.getView(this);
chartView.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.FILL_PARENT, 1f));
LinearLayout layout = (LinearLayout) findViewById(R.id.linearview);
layout.addView(chartView, 0);
}
}
activity的graph:
public class graph {
public View getView(Context context) (...etc.)
谢谢:-D
设置一个handler,当执行需要更改ui的时候,通过handler.sentMessage去通知handle里面去更改UI.
异步方法种怎么能更新UI呢,设置一个Handler,
在onPostExecute()方法种发送一个handler.sentMessage();通知handler更新UI;