Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ViewPager-TabLayout bug about loosing the tab icons. #643 #656

Merged
merged 1 commit into from
Jan 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions opentasks/src/main/java/org/dmfs/tasks/TaskListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,7 @@ protected void onCreate(Bundle savedInstanceState)
// Bind the tabs to the ViewPager
mTabs = (TabLayout) findViewById(R.id.tabs);
mTabs.setupWithViewPager(mViewPager);

// set up the tab icons
for (int i = 0, count = mPagerAdapter.getCount(); i < count; ++i)
{
mTabs.getTabAt(i).setIcon(mPagerAdapter.getTabIcon(i));
}
setupTabIcons();

mViewPager.addOnPageChangeListener(new OnPageChangeListener()
{
Expand Down Expand Up @@ -347,6 +342,15 @@ public void onClick(View v)
}


private void setupTabIcons()
{
for (int i = 0, count = mPagerAdapter.getCount(); i < count; ++i)
{
mTabs.getTabAt(i).setIcon(mPagerAdapter.getTabIcon(i));
}
}


@Override
protected void onResume()
{
Expand Down Expand Up @@ -528,6 +532,11 @@ public void onActivityResult(int requestCode, int resultCode, Intent intent)
Uri newTaskUri = intent.getData();
displayIntent.setData(newTaskUri);
onNewIntent(displayIntent);

/* Icons have to be refreshed here because of some bug in ViewPager-TabLayout which causes them to disappear.
See https://github.com/dmfs/opentasks/issues/643
and https://stackoverflow.com/questions/42209046/tablayout-icons-disappear-after-viewpager-refresh */
setupTabIcons();
}
}

Expand Down