私はすでにDialogFragmentを書いています。AlertDialog と同じように、正と負のボタンが必要であることに気付きました。私が書いたコードを維持しながら、どうすればそのようなことを達成できますか?
public class DoublePlayerChooser extends DialogFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL,0);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle("title")
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// do something...
}
}
)
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
}
)
.create();
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.doubleplayerchooser, container, false);
getDialog().setTitle("Enter Players");
firstPlayerPicker = (ImageButton) v.findViewById(R.id.imageButton1);
firstPlayerPicker.setOnClickListener(new OnClickListener() {
public void onClick(final View v){
callContactPicker(1);
}
});
secondPlayerPicker = (ImageButton) v.findViewById(R.id.ImageButton01);
secondPlayerPicker.setOnClickListener(new OnClickListener() {
public void onClick(final View v){
callContactPicker(2);
}
});
loadFromFile = (ImageButton) v.findViewById(R.id.imageButton2);
loadFromFile.setOnClickListener(new OnClickListener() {
public void onClick(final View v){
}
});
firstTextfield = (EditText) v.findViewById(R.id.editText1);
secondTextfield = (EditText) v.findViewById(R.id.EditText01);
firstImage = (ImageView) v.findViewById(R.id.imageView1);
secondImage = (ImageView) v.findViewById(R.id.ImageView01);
return v;
}