onclicklistener in fragment with intent

Good morning together,

i have an an android app with an Intro class. This Intro class has got three fragments.

in fragment 3 (IntroPage3) i would like to set an onclicklistener with an intent form the IntroPage3 to Overview.class like this:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    FragementView = inflater.inflate(R.layout.intro_page1, container, false);

    Button FinishIntroButton = (Button) FragementView.findViewById(R.id.FinishIntroButton);
    FinishIntroButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            intent = new Intent(IntroPage3.this, Overview.class);
            startActivityForResult(intent, 0);
        }
    });


    return FragementView;
}

Problem: is this line:

intent = new Intent(IntroPage3.this, Intro.class);

Error message:

Any ideas? :)

Answers


use intent = new Intent(getActivity(), Overview.class);


You must use getActivity() instead of IntroPage3.this

WHY

getActivity() in a Fragment returns the Activity the Fragment is currently associated with.

Button FinishIntroButton = (Button) FragementView.findViewById(R.id.FinishIntroButton);
FinishIntroButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        intent = new Intent(getActivity(), Overview.class);
        startActivityForResult(intent, 0);
    }
});

Need Your Help

how to link to WebMethod when using jQuery treeview?

jquery treeview

I'm using jQuery treeview plugin to populate a child treeview once click a folder node to expand. but $("#tv").treeview({url: webservice/webmethod}); but doesn't work, and failed to call webthod. H...

IIS ApplicationPoolIdentity does not have write permission to 'Temporary ASP.NET Files'

asp.net iis windows-8

I am attempting to launch a website from an 'AppPool' called 'SomeAppPool' which uses the 'ApplicationPoolIdentity' and when I do I receive the following error when I launch the website: