Answers for "open new activity from fragment"

1

how to open an activity from a fragment

Button btn1 = (Button) thisLayout
            .findViewById(R.id.btnDb1);

    btn1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(getActivity(), otherActivity.class);
            ((MainActivity) getActivity()).startActivity(intent);

        }
    });

    return thisLayout;
}
Posted by: Guest on May-27-2020
0

open new fragment from fragment

button.setOnClickListener {
    activity!!
        .supportFragmentManager
        .beginTransaction()
        .replace(R.id.container, NewFragment.newInstance())
        .commitNow()
}
Posted by: Guest on March-08-2021

Code answers related to "open new activity from fragment"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language