FragmentComments is a fragment,which has a button.And on this button press a dialog opens(asking whether you want to exit or not).If no is pressed,it does nothing and closes dialog,when yes is pressed,it finishes the current activity,and opens some other random activity.BUT I want it to open another specific activity (say newactivity).How can I do this ?
public class FragmentComments extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_comments, container, false);
Button submit = (Button) view.findViewById(R.id.submit);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
// set title
alertDialogBuilder.setTitle("Submit");
// set dialog message
alertDialogBuilder
.setMessage("Are you sure,you want to submit the feedback ?")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, close
// current activity
FragmentComments.this.getActivity().finish();
//What should I add here to finish the current activity as well as open a new other activity(say newactivity).
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
// if this button is clicked, just close
// the dialog box and do nothing
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
return view;
}
}