therealshabi/AutoImageFlipper

I CAN'T USE SLIDER IN FRAGMENT PLS HELP

Closed this issue · 1 comments

public class FragmentLauncherHome extends Fragment {

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_launcher_home, container, false);

    FlipperLayout flipperLayout = (FlipperLayout) view.findViewById(R.id.flipper_layout);

        FlipperView view2 = new FlipperView(getActivity().getBaseContext());
        view2.setImageUrl("https://source.unsplash.com/random")

// .setImageDrawable(R.drawable.banner_1) // Use one of setImageUrl() or setImageDrawable() functions, otherwise IllegalStateException will be thrown
.setImageScaleType(ImageView.ScaleType.CENTER_CROP) //You can use any ScaleType
.setDescription("Description")
.setOnFlipperClickListener(new FlipperView.OnFlipperClickListener() {
@OverRide
public void onFlipperClick(FlipperView flipperView) {
//Handle View Click here
}
});
flipperLayout.setScrollTimeInSec(5); //setting up scroll time, by default it's 3 seconds
flipperLayout.getScrollTimeInSec(); //returns the scroll time in sec
flipperLayout.getCurrentPagePosition(); //returns the current position of pager
flipperLayout.addFlipperView(view2);

    return view;
}

}

error :
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void technolifestyle.com.imageslider.FlipperLayout.setScrollTimeInSec(int)' on a null object reference

Jejid commented

Hi¡ my english isnt the best but i could implement it in a fragment MainFragment.zip, maybe it can helps you. u can see it funtional in my app: bit.ly/domiyiacacias
here is part of my code:

` public class MainFragment extends Fragment implements View.OnClickListener {
// TODO: Rename parameter arguments, choose names that match
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";

// TODO: Rename and change types of parameters
private String mParam1;
private String mParam2;

private FlipperLayout flipper; // CREATED FLIPPER IN FRAGMENT

private  View vista;
ImageView clasif0,clasif1,clasif2,clasif3,clasif4,clasif5,clasif6,clasif7,clasif10;
private TextView clasif0t,clasif1t,clasif2t,clasif3t,clasif4t,clasif5t,clasif6t,clasif7t,clasif10t,numeroDomiYi;
private String currentVersion = BuildConfig.VERSION_NAME;
private ArrayList<Establecimiento> BannerSecondShot;


private OnFragmentInteractionListener mListener;

public MainFragment () {
    // Required empty public constructor
} `