intent open fragment code example
Example 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) {
Intent intent = new Intent(getActivity(), otherActivity.class);
((MainActivity) getActivity()).startActivity(intent);
}
});
return thisLayout;
}
Example 2: intent in fragment android
Button button = (Button) rootView.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getActivity(), AnotherActivity.class);
startActivity(intent);
}
});