Issue
I use fragments with viewPager. One of fragment use asynctask to download data. Now the problem is the task hasn't finish but fragment's onCreateView return already. Can I update fragment while task finished? I tried to call view.invalidate() is not working.
public class LineChartFragment extends Fragment {
View view;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
new Background().execute();
return view;
}
}
class Background extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
}
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
if (haveInternet()) {
getter();
}
return null;
}
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
//UPDATE fragment
....
view = ChartFactory.getLineChartView(getActivity().getApplicationContext(), dataset, renderer);
....
view.invalidate();
}
Solution
I found this Calling a class from a fragment
inflate a linearLayout and add chart view to the layout. Thanks!
Answered By - JackWu
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.