FragmentComments是一个片段,它有一个按钮。在这个按钮上按下一个对话框打开(询问是否要退出)。如果没有按下,它什么都不做,关闭对话框,当按下是,它完成当前的活动,并打开一些其他随机活动。但我希望它打开另一个特定的活动(比如newactivity)。我怎么能这样做?
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();
//我应该在这里添加什么来完成当前活动以及打开一个新的其他活动(比如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;
}
}