Problem with Tabs and Adapter

Asked

Viewed 50 times

0

I got a problem here.

I have that code

Home Screen: inserir a descrição da imagem aqui

public class Inicial extends AppCompatActivity {


private ImageButton button,button2;


        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_inicial);

            button = (ImageButton)findViewById(R.id.imageButton8);

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

                    Intent it = new Intent(Inicial.this,MainActivity1.class);
                    startActivity(it);
                }
            });

            button2 = (ImageButton)findViewById(R.id.imageButton5);




    }}

Mainactivity:

inserir a descrição da imagem aqui

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
    tabLayout.addTab(tabLayout.newTab().setText("Praça XV - Araribóia"));
    tabLayout.addTab(tabLayout.newTab().setText("Araribóia - Praça XV"));
    tabLayout.addTab(tabLayout.newTab().setText("Tempo de viagem"));
    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.addOnPageChangeListener(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) {

        }
    });
}}

Pageadapter

class PagerAdapter extends FragmentStatePagerAdapter {
    int mNumOfTabs;
public PagerAdapter(FragmentManager fm, int NumOfTabs) {
    super(fm);
    this.mNumOfTabs = NumOfTabs;
}

@Override
public Fragment getItem(int position) {

    switch (position) {
        case 0:
            TabFragment1 tab1 = new TabFragment1();
            return tab1;
        case 1:
            TabFragment2 tab2 = new TabFragment2();
            return tab2;
        case 2:
            TabFragment3 tab3 = new TabFragment3();
            return tab3;
        default:
            return null;
    }
}

    @Override
    public int getCount() {
        return mNumOfTabs;
    }
}

All with their respective xml.

Now with the photos, I want to click on another station, for examples PRACA XV - CHARITAS and open a screen equal to SECOND photo but of course with different times and etc.

Now I want to add another button on the HOME SCREEN so that when the user presses it opens another screen identical to this MAIN ACTIVITY only with other information. Like it was a MAIN ACTIVITY2.

I copied and pasted changing the id’s and is giving direct crash.

What can it be?

ERROR CODE WHEN CRASH

06-08 09:06:45.398 7073-7073/com.applicatitivos.facilitates.E/Androidruntime test: FATAL EXCEPTION: main Process: com.applitivos.facilitates.test, PID: 7073 android.content.Activitynotfoundexception: Unable to find Explicit Activity class {com.applicatitivos.facilitates.test/com.applicatitivos.facilitates.teste.Mainactivity1}; have you declared this Activity in your Androidmanifest.xml? at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1628) at android.app.Instrumentation.execStartActivity(Instrumentation.java:1424) at android.app.Activity.startActivityForResult(Activity.java:3424) at android.support.v4.app.Basefragmentactivityjb.startActivityForResult(Basefragmentactivityjb.java:50) at android.support.v4.app.Fragmentactivity.startActivityForResult(Fragmentactivity.java:79) at android.app.Activity.startActivityForResult(Activity.java:3385) at android.support.v4.app.Fragmentactivity.startActivityForResult(Fragmentactivity.java:859) at android.app.Activity.startActivity(Activity.java:3627) at android.app.Activity.startActivity(Activity.java:3595) at com.applitivos.facilitates.teste.Home$2.onClick(Initial.java:44) at android.view.View.performClick(View.java:4438) at android.view.View$Performclick.run(View.java:18422) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.Activitythread.main(Activitythread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.Internal.os.Zygoteinit$Methodandargscaller.run(Zygoteinit.java:785) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:601) at Dalvik.system.Nativestart.main(Native Method)

  • You can put the mistakes they made?

  • No mistake.. the moment I click on the other button that was to open another screen with the tabs the app closes.

  • @Marioandrefro no compile error, error when crash app

  • @leofontes is this msm. I wanted to put the picture of the screens to explain better but I’m not getting

  • You said you’re giving crash, so it’s a mistake. You have to show what says when this error happens. Just look at the android monitor.

  • @Marceloawq put it now

  • 1

    @Marceloawq Thanks to you I discovered what it was by android monitor. Activity was not in Manifest! Thanks

  • Opa @Marioandréfranco so that’s right! Try not to create activities copying and pasting the java and xml, always use the menu new right-clicking on the package.

Show 3 more comments
No answers

Browser other questions tagged

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