Tap Close App button

Asked

Viewed 91 times

0

Follow this tutorial to create a layout with tabs.

After that, I created an XML button, which is displayed without action, because it is only in XML.

I want to open another Activity from the touch of this button, but when you touch it, the application closes. Even though I have already declared the new Activity in the Manifest, the problem persists.

Where is the error? How should the action of this button be declared?

Follow the codes:

Principalactivity.java

public class PrincipalActivity extends FragmentActivity implements ActionBar.TabListener {

ActionBar barDimens;
ViewPager pagerDimens;
FragmentPageAdapter fpaDimens;

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


    pagerDimens = (ViewPager) findViewById(R.id.pager_dimens);
    fpaDimens = new FragmentPageAdapter(getSupportFragmentManager());

    barDimens = getActionBar();
    pagerDimens.setAdapter(fpaDimens);
    barDimens.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    barDimens.addTab(barDimens.newTab().setText("VIGAS").setTabListener(this));
    barDimens.addTab(barDimens.newTab().setText("PILARES").setTabListener(this));

    pagerDimens.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageSelected(int arg0) {
            barDimens.setSelectedNavigationItem(arg0);

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {


        }

        @Override
        public void onPageScrollStateChanged(int arg0) {


        }
    });
} // fecha onCreate

@Override
public void onTabSelected(Tab tab, FragmentTransaction ft) {
    pagerDimens.setCurrentItem(tab.getPosition());

}

@Override
public void onTabUnselected(Tab tab, FragmentTransaction ft) {


}

@Override
public void onTabReselected(Tab tab, FragmentTransaction ft) {


}
}

activity_main.xml

<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager_dimens"
android:layout_width="match_parent"
android:layout_height="match_parent" >

Vigasfragment.java

public class VigasFragment extends Fragment implements OnClickListener {
Button btnBiapsb;

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

    btnBiapsb = (Button) rootView.findViewById(R.id.biapsb);
    btnBiapsb.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intBiapsb = new Intent(v.getContext(), VigMetBiapsb.class);
            startActivityForResult(intBiapsb, 0);
        }
    });
    return rootView;

}// fecha onCreateView

@Override
public void onClick(View v) {
    // TODO Auto-generated method stub
}

}

vigas_fragment.xml

<?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ScrollView01"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#F8F8F8" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="15dp"
    android:paddingRight="15dp"
    android:paddingBottom="15dp" >

    <TextView
        android:id="@+id/vigasmet"
        android:text="@string/vigasmetalicas"
        style="@style/subtitulos" />

    <Button
        android:id="@+id/biapsb"
        android:layout_below="@+id/vigasmet"
        android:text="@string/biapsb"
        android:drawableLeft="@drawable/vigabiap2"
        style="@style/botoesdimens" />

</RelativeLayout>

</ScrollView>
  • Any error appears in Logcat?

  • Several appear, but I still do not know how to interpret them, rs. Here is a print: http://image.noelshack.com/fichiers/2014/47/1416535099-imagem1.png (sorry for the image distortion, I don’t know why it got like this)

  • Remove this Onclicklistener Implements from the Vigasfragment class along with its Override method

  • in new Intent vc puts getActivity() as context instead of v.getcontext(), or if there is no such method you use getApplicationContext(). ---------------> Intent intBiapsb = new Intent(getActivity(), Vigmetbiapsb.class);

  • Edeilton, your class VigMetBiapsb is a subclass of Activity?

  • @Wakim No, she is Activity itself (I managed to solve the problem with the first tip from Juarez A. Franco Junior, even said that and now the comment is not here, rs. Anyway, thank you very much!)

Show 1 more comment
No answers

Browser other questions tagged

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