ProgressBar Does Not Update in Fragment

I have a ProgressBar in my app that represent a static value, the value is got from server.

My code in Fragment is in onCreateView, follows:

public class AgeFragment extends Fragment {

List tableStatsCacheList;
String place,partial1,partial2, partial3, partial4, partial5, partial6;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    TextView placeTextView;
    TextView partial1TextView, partial2TextView, partial3TextView, partial4TextView, partial5TextView, partial6TextView;
    ProgressBar bar1ProgressBar, bar2ProgressBar, bar3ProgressBar, bar4ProgressBar, bar5ProgressBar, bar6ProgressBar;

    readTableStatsCache();

    View rootView = inflater.inflate(R.layout.fragment_age, container, false);

    placeTextView = (TextView) rootView.findViewById(R.id.placeTextView);

    partial1TextView = (TextView) rootView.findViewById(R.id.partial1TextView);
    partial2TextView = (TextView) rootView.findViewById(R.id.partial2TextView);
    partial3TextView = (TextView) rootView.findViewById(R.id.partial3TextView);
    partial4TextView = (TextView) rootView.findViewById(R.id.partial4TextView);
    partial5TextView = (TextView) rootView.findViewById(R.id.partial5TextView);
    partial6TextView = (TextView) rootView.findViewById(R.id.partial6TextView);
    bar1ProgressBar = (ProgressBar) rootView.findViewById(R.id.bar1ProgressBar);
    bar2ProgressBar = (ProgressBar) rootView.findViewById(R.id.bar2ProgressBar);
    bar3ProgressBar = (ProgressBar) rootView.findViewById(R.id.bar3ProgressBar);
    bar4ProgressBar = (ProgressBar) rootView.findViewById(R.id.bar4ProgressBar);
    bar5ProgressBar = (ProgressBar) rootView.findViewById(R.id.bar5ProgressBar);
    bar6ProgressBar = (ProgressBar) rootView.findViewById(R.id.bar6ProgressBar);

    placeTextView.setText(place);
    partial1TextView.setText(partial1+"%");
    partial2TextView.setText(partial2+"%");
    partial3TextView.setText(partial3+"%");
    partial4TextView.setText(partial4+"%");
    partial5TextView.setText(partial5+"%");
    partial6TextView.setText(partial6+"%");

    bar1ProgressBar.setProgress(Math.round(Float.valueOf(partial1)));
    bar2ProgressBar.setProgress(Math.round(Float.valueOf(partial2)));
    bar3ProgressBar.setProgress(Math.round(Float.valueOf(partial3)));
    bar4ProgressBar.setProgress(Math.round(Float.valueOf(partial4)));
    bar5ProgressBar.setProgress(Math.round(Float.valueOf(partial5)));
    bar6ProgressBar.setProgress(Math.round(Float.valueOf(partial6)));

    return rootView;
}

public void readTableStatsCache(){

    DatabaseHandlerTableStatsCache db_read = new DatabaseHandlerTableStatsCache(CallFragment.context);

    tableStatsCacheList = db_read.getAllLines();       

    for (TableStatsCache cn : tableStatsCacheList) {

        place = cn.getPlace();
        partial1 = cn.getPartial1();
        partial2 = cn.getPartial2();
        partial3 = cn.getPartial3();
        partial4 = cn.getPartial4();
        partial5 = cn.getPartial5();
        partial6 = cn.getPartial6();

    }
    }
}

This fragment show the ProgressBar correct when is created, but when my FragmentActivity reload the Fragment the ProgressBar is not updated. Only the TextView is updated.

For reload a fragment, i have this in FragmentActivity:

viewPager.removeAllViews();
    viewPager.setAdapter(mAdapter);

I think that a problem can be because the method “setProgress” is synchronized.

How i release the old thread to a new thread can run the method?

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 移动开发 » ProgressBar Does Not Update in Fragment

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录