我創建了一個DialogFragment,我想補充一個EditText,但是當我嘗試添加它是這樣的:如何將EditText添加到DialogFragment?
final EditText input = new EditText(this);
我上「這個」說「的構造函數的EditText(EncryptionDialogFragment)的錯誤未定義」。
我的最終目標是讓用戶以這種方式輸入密碼。
public class EncryptionDialogFragment extends DialogFragment {
final EditText input = new EditText(this);
static EncryptionDialogFragment newInstance(String title){
EncryptionDialogFragment fragment = new EncryptionDialogFragment();
Bundle args = new Bundle();
args.putString("title", title);
fragment.setArguments(args);
return fragment;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setIcon(R.drawable.ic_launcher)
.setTitle("Enter Password:")
.setView(input)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
((MainActivity)getActivity()).doPositiveClick();
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int whichButton) {
((MainActivity)getActivity()).doNegativeClick();
}
}).create();
}
}
謝謝!我只需要等10分鐘來接受你的答案。 – GreekOphion