Error using startActivity on Fragment

Asked

Viewed 22 times

1

I want the Button (tutorialeme) that is inside the "emergency" Ragment to have a CLICK action, and in this action I want him to call the Activity "tabbed_warning", the error is in Intent, specifically emergencia.this, android studio indicates this error:

Cannot resolve constructor 'Intent(app.conect.medicconect1.emergencia, java.lang.Class)'

or in Portuguese:

Unable to resolve 'Intent(app.conect.medicconect1.Emergency, java.lang.Class constructor )'.

HERE IS THE JAVA OF THE FRAGMENT "EMERGENCY":

package app.conect.medicconect1;

import android.content.Intent;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;

import android.widget.Button;

import androidx.fragment.app.Fragment;

public class emergencia extends Fragment {

    Button tutorialeme;

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

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        tutorialeme = (Button) container.findViewById(R.id.tutorialeme);

        tutorialeme.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent tuto = new Intent(emergencia.this, tabbed_warning.class);
                startActivity(tuto);
            }
        });
        return inflater.inflate(R.layout.fragment_emergencia, container, false);
    }
}

HERE IS THE XML OF THE "EMERGENCY" FRAGMENT WHERE THE BUTTON IS:

<Button
        android:id="@+id/tutorialeme"
        android:layout_width="157dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="0dp"
        android:layout_marginBottom="15dp"
        android:background="@null"
        android:text="Não entendi ?"
        style="?android:attr/borderlessButtonStyle"
        android:textColor="@color/colorgray"
        android:textSize="15dp" />

HERE IS THE JAVA OF ACTIVITY "TABBED_WARNING":

here in case there is no visible error

package app.conect.medicconect1;

public class tabbed_warning extends AppCompatActivity implements Tab1.OnFragmentInteractionListener, Tab2.OnFragmentInteractionListener, Tab3.OnFragmentInteractionListener{

    private ImageButton bttvoltar;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tabbed_warning);

        bttvoltar = (ImageButton) findViewById(R.id.bttvoltar);
        bttvoltar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent abreHome = new Intent(tabbed_warning.this, emergencia.class);
                startActivity(abreHome);
            }
        });

        TabLayout tabLayout = (TabLayout)findViewById(R.id.tablayout);
        tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
        tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
        tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
        tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);

        final ViewPager viewPager = (ViewPager)findViewById(R.id.pager);
        final PagerAdapter adapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount());
        viewPager.setAdapter(adapter);
        viewPager.setOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));

        tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                viewPager.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });

    }

    @Override
    public void onFragmentInteraction(Uri uri) {

    }
}
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.