我尝试过->在viewpager片段中实现的接口,但是默认情况下,第一个片段仅在我滚动页面或轻按水龙头时才获得界面的功能,我想在第一个片段上设置界面的功能。
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.BaseOnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
final Fragment fragment =adapter.getRegisteredFragment(tab.getPosition());
// int position1=(int)fragment.getArguments().get("position");
// final Fragment fragment1=frag[position1];
//fragment1.onAttach(Orders_Activity.this);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Utils.printValue("reached ","tabselected");
//fragmentCommunicatorObj = new OrdersPending();
fragmentCommunicatorObj =(fragmentCommunicator) fragment;
fragmentCommunicatorObj.passDataToFragment("Hello I am created",getApplicationContext());
}
});
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});