As showing in the above picture, I have created a Fragment named CustomerFragLogin with the code as follows :-
public class customerFragLogin extends Fragment {
private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2";
private String mParam1;
private String mParam2;
public customerFragLogin() {
// Required empty public constructor
}
public static customerFragLogin newInstance(String param1, String param2) {
customerFragLogin fragment = new customerFragLogin();
Bundle args = new Bundle();
args.putString(ARG_PARAM1, param1);
args.putString(ARG_PARAM2, param2);
fragment.setArguments(args);
return fragment;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.frag_customer_login, container, false);
}
}
Now, when I click on 'Login' button or 'Forget password' textview I want to open a new activity. How do I implement this ?
add this to your CustomerFragLogin
@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
TextView textView= findViewById(R.id.textView)
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(new Intent(getActivity(), NewActivity.class));
}
});
}
make sure your activity is declared in the manifest