Giter VIP home page Giter VIP logo

Comments (7)

heinrichreimer avatar heinrichreimer commented on July 19, 2024

Are you using FragmentSlide with a layout resource or with a custom Fragment?
Normally if you're using a custom Fragment you should override the Fragment's onCreateView() and inflate/find all views there and then add click listeners or such.

from material-intro.

panospcm avatar panospcm commented on July 19, 2024

Thank you for your reply, congrats on your development skills.
Could you maybe show me an example with a custom Fragment? Because in your documentation I only see a layout resource example.

This is my current code snippet:
addSlide(new FragmentSlide.Builder()
.background(R.color.md_blue_grey_100)
.backgroundDark(R.color.md_blue_grey_600)
.fragment(R.layout.fragment_login, R.style.AppTheme)
.build());

All i want is to create an onclicklistener for a button inside R.layout.fragment_login.

from material-intro.

heinrichreimer avatar heinrichreimer commented on July 19, 2024

First create a LoginFragment class extending Fragment as described here:
http://developer.android.com/training/basics/fragments/creating.html#Create
(You'll just need to follow the steps in chapter 'Create a Fragment Class'.)

To use click events from a button inside your LoginFragment refer to this guide:
http://developer.android.com/training/basics/firstapp/starting-activity.html#RespondToButton
(Again, just follow the steps in 'Respond to the Send Button'.)

Then add your LoginFragment to the intro like this:

addSlide(new FragmentSlide.Builder()
                .background(R.color.md_blue_grey_100)
                .backgroundDark(R.color.md_blue_grey_600)
                .fragment(new LoginFragment())
                .build());

I hope this explanation helps you!

from material-intro.

panospcm avatar panospcm commented on July 19, 2024

Yes, i tried what you suggested and i get an error 'Cannot resolve method 'fragment(LoginFragment)' .
The LoginFragment is not the issue here, I think, because it works if i load it in another activity.

from material-intro.

heinrichreimer avatar heinrichreimer commented on July 19, 2024

Can you post your LoginFragment code and the exact code where you add the slide here?

from material-intro.

panospcm avatar panospcm commented on July 19, 2024

LoginFragment.java :

public class LoginFragment extends Fragment {
    // 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 OnFragmentInteractionListener mListener;

    public LoginFragment() {
        // Required empty public constructor
    }

    // TODO: Rename and change types and number of parameters
    public static LoginFragment newInstance(String param1, String param2) {
        LoginFragment fragment = new LoginFragment();
        Bundle args = new Bundle();
        args.putString(ARG_PARAM1, param1);
        args.putString(ARG_PARAM2, param2);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments() != null) {
            mParam1 = getArguments().getString(ARG_PARAM1);
            mParam2 = getArguments().getString(ARG_PARAM2);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_login, container, false);
    }

    // TODO: Rename method, update argument and hook method into UI event
    public void onButtonPressed(Uri uri) {
        if (mListener != null) {
            mListener.onFragmentInteraction(uri);
        }
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        if (context instanceof OnFragmentInteractionListener) {
            mListener = (OnFragmentInteractionListener) context;
        } else {
            throw new RuntimeException(context.toString()
                    + " must implement OnFragmentInteractionListener");
        }
    }

    @Override
    public void onDetach() {
        super.onDetach();
        mListener = null;
    }

    public interface OnFragmentInteractionListener {
        // TODO: Update argument type and name
        void onFragmentInteraction(Uri uri);
    }
}

Now, MaterialIntroActivity.java (as seen on your repo)

public class MaterialIntroActivity extends IntroActivity {

    public static final String EXTRA_FULLSCREEN = "com.heinrichreimersoftware.materialintro.demo.EXTRA_FULLSCREEN";
    public static final String EXTRA_CUSTOM_FRAGMENTS = "com.heinrichreimersoftware.materialintro.demo.EXTRA_CUSTOM_FRAGMENTS";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Intent intent = getIntent();

        boolean fullscreen = intent.getBooleanExtra(EXTRA_FULLSCREEN, false);
        boolean customFragments = intent.getBooleanExtra(EXTRA_CUSTOM_FRAGMENTS, false);

        setFullscreen(fullscreen);

        super.onCreate(savedInstanceState);

        addSlide(new SimpleSlide.Builder()
                .title(R.string.title_material_metaphor)
                .description(R.string.description_material_metaphor)
                .image(R.drawable.art_material_metaphor)
                .background(R.color.color_material_metaphor)
                .backgroundDark(R.color.color_dark_material_metaphor)
                .build());
        addSlide(new SimpleSlide.Builder()
                .title(R.string.title_material_bold)
                .description(R.string.description_material_bold)
                .image(R.drawable.art_material_bold)
                .background(R.color.color_material_bold)
                .backgroundDark(R.color.color_dark_material_bold)
                .build());
        addSlide(new SimpleSlide.Builder()
                .title(R.string.title_material_motion)
                .description(R.string.description_material_motion)
                .image(R.drawable.art_material_motion)
                .background(R.color.color_material_motion)
                .backgroundDark(R.color.color_dark_material_motion)
                .build());
        addSlide(new SimpleSlide.Builder()
                .title(R.string.title_material_shadow)
                .description(R.string.description_material_shadow)
                .image(R.drawable.art_material_shadow)
                .background(R.color.color_material_shadow)
                .backgroundDark(R.color.color_dark_material_shadow)
                .build());

        if(customFragments){
            addSlide(new FragmentSlide.Builder()
                    .background(R.color.color_custom_fragment_1)
                    .backgroundDark(R.color.color_dark_custom_fragment_1)
                    .fragment(new LoginFragment())  // **## ERROR IS HERE**
                    .build());
            addSlide(new FragmentSlide.Builder()
                    .background(R.color.color_custom_fragment_2)
                    .backgroundDark(R.color.color_dark_custom_fragment_2)
                    .fragment(R.layout.fragment_custom_2, R.style.AppTheme)
                    .build());
        }

        //Feel free to add and remove page change listeners to request permissions or such
        /*
        addOnPageChangeListener(new ViewPager.OnPageChangeListener(){
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
        */
    }
}

from material-intro.

heinrichreimer avatar heinrichreimer commented on July 19, 2024

Now I see the issue. Currently FragmentSlide accepts only FragmentSlide.Fragments as parameter. I'll fix this soon.

from material-intro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.