這是我的代碼,請檢查一下告訴我是什麼問題。大多數情況下,第二次滑動時不會順滑地滑動fragment
。我與FragmentPagerAdapter
和覆蓋getItemPosition()
方法檢查,但無法找到解決方案。查看傳呼機不能順利滑動
//View Pager Adapter
public class MyBookingPagerAdapter extends FragmentStatePagerAdapter{
private ArrayList<Booking> bookingList;
public MyBookingPagerAdapter(FragmentManager fm,ArrayList<Booking> bookingList) {
super(fm);
this.bookingList=bookingList;
}
@Override
public Fragment getItem(int position) {
return MyBookingFragment.newInstance(bookingList.get(position));
}
@Override
public int getCount() {
return bookingList.size();
}
@Override
public int getItemPosition(Object object) {
return POSITION_NONE;
}
}
//View Pager Fragment
public class MyBookingFragment extends BaseFragment {
private Booking booking;
private RelativeLayout containerTopView;
private TextView txtTitle,txtAddress,txtDay,txtMonth,txtShowDayName,txtShowDate,txtLastEntyTime,txtFemalesprice,txtCouplePrice,txtMalesPrice,txtTotalAmount;
private ImageView imgTopView;
private LinearLayout dotsContainer;
public static MyBookingFragment newInstance(Booking booking){
MyBookingFragment fragmentMyBooking= new MyBookingFragment();
Bundle args=new Bundle();
args.putSerializable("booking",booking);
fragmentMyBooking.setArguments(args);
return fragmentMyBooking;
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view=inflater.inflate(R.layout.fragment_my_booking_appbar,container,false);
// init Layout view (find View By Id from the xml)
initViews(view);
// Set booking values of views
if(booking!=null)
setValues(booking);
return view;
}
private void setValues(Booking booking) {
txtTitle.setText(booking.getEventName());
txtAddress.setText(booking.getAddress());
txtShowDayName.setText(booking.getDayName());
txtShowDate.setText(booking.getBookingDate());
txtLastEntyTime.setText(booking.getBookingTime());
txtFemalesprice.setText(booking.getFemale()+" x +getString(R.string.Rs)+booking.getLaydiesPrice());
txtMalesPrice.setText(booking.getMale()+" x "+getString(R.string.Rs)+booking.getStageEntryPrice());
txtCouplePrice.setText(booking.getCouple()+" x "+getString(R.string.Rs)+booking.getCouplePrice());
txtTotalAmount.setText(booking.getTotalPrice());
try{
ImageLoader.getInstance().displayImage(booking.getImgTopView(),imgTopView);
}catch (Exception e){
Utils.print("MyBookingFragment ImageLoader",e.toString());
}
}
private void initViews(View view) {
txtShowDayName= (TextView) view.findViewById(R.id.txtMyBookingShowDay);
txtShowDate= (TextView) view.findViewById(R.id.txtMyBookingShowDate);
txtLastEntyTime= (TextView) view.findViewById(R.id.txtMyBookingLastEntryTime);
txtFemalesprice= (TextView) view.findViewById(R.id.txtMyBookingFemalePrice);
txtMalesPrice= (TextView) view.findViewById(R.id.txtMyBookingMalesPrice);
txtCouplePrice= (TextView) view.findViewById(R.id.txtMyBookingCouplePrice);
txtTotalAmount= (TextView) view.findViewById(R.id.txtMyBookingTotal);
txtAddress= (TextView) view.findViewById(R.id.txtMyBookingAddress);
txtTitle= (TextView) view.findViewById(R.id.txtMyBookingTitle);
imgTopView=(ImageView) view.findViewById(R.id.imgTopView);
containerTopView= (RelativeLayout) view.findViewById(R.id.containerTopView);
booking= (Booking) getArguments().getSerializable("booking");
}
}
//Setting View Pager Adapter
adapter=new MyBookingPagerAdapter(getSupportFragmentManager(),bookingArrayList);
pager.setAdapter(adapter);
pager.setOffscreenPageLimit(3);
// showing no data msg view
if(adapter.getCount()<=0)
findViewById(R.id.frameNoData).setVisibility(View.VISIBLE);
else{
setIndicators(bookingArrayList.size());
pager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
@Override
public void onPageSelected(int position) {
if(indicators!=null)
indicators[position].setChecked(true);
}
@Override
public void onPageScrollStateChanged(int state) { } });
可能是任何內存問題,請在具有良好規格的其他設備上嘗試,並解決它 – Androider