[OK]ボタンをクリックすると、NULLポインタ例外が発生します。私はAlertDialogでEditTextの値を取得しようとしています。私はフラグメントからAlertDialogを呼び出しています。フラグメント内のAlertDialogからEditText値を取得しているAndroid
私はこの行が問題だと思っています View promptView = layoutInflater.inflate(R.layout.passchange_dialog、null); 私はnullを渡しているからだと思うが、私は何を渡すべきか分からない。私は、アクティビティではなくフラグメントからAlertDialogを呼び出すことに注意してください。
public class fragment_account extends myFragment {
private final String firebase = "https://xxxxxxxx.firebaseio.com";
private String email = "";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_account, container, false);
SharedPreferences sp = getActivity().getPreferences(0);
TextView address = (TextView) view.findViewById(R.id.textViewEmailAddress);
email = sp.getString("email", "");
address.setText(email);
ImageView imageChangePass = (ImageView) view.findViewById(R.id.imageChangePass);
imageChangePass.setOnClickListener(
new View.OnClickListener() {
public void onClick(View v) {
showInputDialog(v);
}
}
);
return view;
}
protected void showInputDialog(final View view) {
try
{
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View promptView = layoutInflater.inflate(R.layout.passchange_dialog, null);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(view.getContext());
alertDialogBuilder.setView(promptView);
alertDialogBuilder.setCancelable(false)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
EditText edittextOldPass = (EditText) view.findViewById(R.id.edittextOldPass);
EditText edittextNewPass = (EditText) view.findViewById(R.id.edittextNewPass);
EditText edittextConfirmPass = (EditText) view.findViewById(R.id.edittextConfirmPass);
final String oldPass = edittextOldPass.getText().toString().trim();
final String newPass = edittextNewPass.getText().toString().trim();
final String confirmPass = edittextConfirmPass.getText().toString().trim();
Firebase ref = new Firebase(firebase);
ref.changePassword(email, oldPass, newPass, new Firebase.ResultHandler() {
@Override
public void onSuccess() {
}
@Override
public void onError(FirebaseError firebaseError) {
}
});
}
})
.setNegativeButton("Cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
catch (Exception e)
{
Log.i("myStuff", e.getMessage());
}
}
}
すべてのヘルプや提案を大幅に理解されるであろう。ありがとう
変数ビューにfindViewByIdを呼ぶべきだと思いますか? –