Evgeny GooDi Evgeny GooDi - 6 months ago 55
Android Question

progressDialog in wrong tab

I have 4 tabs in my application. One of them is for json parsing with progress dialog. But i see progres dialog at another tab.
enter image description here

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_parsing, container, false);
lv = (ListView)view.findViewById(R.id.list);
progressDialog = ProgressDialog.show(lv.getContext(), null, getResources().getString(R.string.connecting), true, true);
MyTask myTask = new MyTask(FragmentParsing.this);
myTask.execute(url);

return view;
}

@Override
public void onTaskComplete(ArrayList<String> array) {
if(array != null) {
//adapter.clear();
arrayList.addAll(array);
adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_list_item_1, arrayList);
lv.setAdapter(adapter);
adapter.notifyDataSetChanged();
}
else
Toast.makeText(getView().getContext(), getResources().getString(R.string.fuck), Toast.LENGTH_SHORT).show();
if (progressDialog != null && progressDialog.isShowing()) {
progressDialog.dismiss();
}
}


And i want to see icons to left of text. Not above.

Code from MainActivity

private void setUI(){
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null){
toolbar.setTitleTextColor(getResources().getColor(R.color.white));
setSupportActionBar(toolbar);
}
TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ic_list_white_18dp).setText(R.string.listtab));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ic_camera_alt_white_18dp).setText(R.string.scalingtab));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ic_web_asset_white_18dp).setText(R.string.parsingtab));
tabLayout.addTab(tabLayout.newTab().setIcon(R.drawable.ic_my_location_white_18dp).setText(R.string.maptab));

final ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
TabAdapter tabAdapter = new TabAdapter(fragmentManager, 4);
viewPager.setAdapter(tabAdapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}

@Override
public void onTabUnselected(TabLayout.Tab tab) {

}

@Override
public void onTabReselected(TabLayout.Tab tab) {

}
});
}

Answer

Its basically android pager workflow. It always creates one adjacent page view as soon as you swipe. You can have logger and check. If I'm not not wrong your fragment pager, you start your progress bar on onResume callback of your fragment.