user3038222
user3038222

Reputation: 25

Fragment of how to move to another class using Intent?

In Fragment I made a button click handler and using Intent want to go to class Karta, but fails. Eclipse fail The constructor Intent(new View.OnClickListener(){}, Class Karta) is undefined (hlkjbhlkbnkl/nk;/n;kn;/nk;/nk;nk;n)

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

public class Fragment1 extends Fragment {

    Button button1;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.fragment1,
                container, false);

        button1=(Button)rootView.findViewById(R.id.button1);

        button1.setOnClickListener (new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent (this,Karta.class);
                startActivity(intent);
            }});

        return rootView;

    }

}

import android.app.Activity;
import android.os.Bundle;

public class Karta extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.karta);

        }
    }

Upvotes: 0

Views: 1695

Answers (1)

Ahmed Zayed
Ahmed Zayed

Reputation: 2185

 Intent intent = new Intent (Fragment1.this.getActivity(),Karta.class);

Upvotes: 2

Related Questions