当我点击导航抽屉项目时,第一个选项卡被选中。 从抽屉中选择第二个项目后,第二个选项卡刚刚被选中几秒钟,它将在第一个选项卡上移动。和其他人一样
the first tab is selected from navigation drawer, it works fine
now as per selected second menu from drawer it automatically move first tab after few seconds
This code block run for view pager
if (Share.getSetCheckVariable().equals("Products")) {
boolean b = true;
Share.setSetCheckVariable("Products");
for (int i = 0; i < productSize; i++) {
fragment = new ImageListFragmentImageListFragment();
bundle = new Bundle();
bundle.putInt("type", i);
fragment.setArguments(bundle);
if (b) {
for (int g = 0; g < subCategories_Size; g++) {
b = false;
adapter.addFragment(fragment, sub_categories.get(g));
}
}
}
}
This code block run when click on navigation drawer item
for (int i = 0; i < subCategories_Size; i++) {
if (id == i) {
Share.setSetCheckVariable("Products");
get_productDetails(sub_categoriesID.get(i));
b = true;
myHandler.postDelayed(new Runnable() {
@Override
public void run() {
productSize = Share.getProduct_name().size();
setupViewPager(viewPager);
}
}, 1000);
break;
}
}
viewPager.setCurrentItem(id);
}
答案 0 :(得分:0)
您没有更改id
的值或i
的值,因此当您运行时:
for (int i = 0; i < subCategories_Size; i++) {
if (id == i) {
Share.setSetCheckVariable("Products");
get_productDetails(sub_categoriesID.get(i));
b = true;
myHandler.postDelayed(new Runnable() {
@Override
public void run() {
productSize = Share.getProduct_name().size();
setupViewPager(viewPager);
}
}, 1000);
break;
}
}
viewPager.setCurrentItem(id);
}
它会显示第一个,因为viewPager.setCurrentItem(id);
有id
= 1。
此外,您应该使用onClickListener
代替