это мой xml файл
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout_name_profile_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/name_profile_hint"
android:theme="@style/AppTheme">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_name_fragment_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:text="mio_nome"
android:inputType="text"
android:enabled="false"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout_lastname_profile_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/last_name_profile_hint"
android:theme="@style/AppTheme">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_lastname_fragment_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="text"
android:enabled="false"
android:maxLines="1"
android:text="mio_cognome" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout_email_profile_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/email_profile_fragment_hint"
android:theme="@style/AppTheme">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_email_fragment_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="text"
android:text="mia_email"
android:enabled="false"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout_password_profile_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/password_profile_hint"
android:theme="@style/AppTheme"
app:endIconMode="password_toggle"
app:endIconTint="@android:color/white">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_password_fragment_profile"
android:text="mia_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:enabled="false"
android:inputType="textPassword"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/text_input_layout_nickname_profile_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/username"
android:theme="@style/AppTheme"
app:counterEnabled="true"
app:counterMaxLength="20">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/edit_text_nickname_fragment_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="text"
android:enabled="false"
android:text="mio_username"
android:maxLines="1" />
</com.google.android.material.textfield.TextInputLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
</RelativeLayout>
А это мой ProfileFragment. java class
public class ProfileFragment extends Fragment {
private EditText editTextName;
private EditText editTextLastName;
private EditText editTextEmail;
private EditText editTextUsername;
private EditText editTextPassword;
private FloatingActionButton floatingActionButton;
private View view;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
view = inflater.inflate(R.layout.fragment_profile, container, false);
initializeViewComponents();
initializeController();
return view;
}
@Nullable
@Override
public View getView() {
return view;
}
public void initializeViewComponents() {
editTextName = view.findViewById(R.id.edit_text_name_fragment_profile);
editTextLastName = view.findViewById(R.id.edit_text_lastname_fragment_profile);
editTextEmail = view.findViewById(R.id.edit_text_email_fragment_profile);
editTextUsername = view.findViewById(R.id.edit_text_nickname_fragment_profile);
editTextPassword = view.findViewById(R.id.edit_text_password_fragment_profile);
floatingActionButton = view.findViewById(R.id.floating_action_button_edit_profile_fragment);
}
public void initializeController() {
ProfileController profileController = new ProfileController(this);
profileController.setListenersOnProfileFragment();
}
public EditText getEditTextPassword() {
return editTextPassword;
}
public FloatingActionButton getFloatingActionButton() {
return floatingActionButton;
}
public EditText getEditTextName() {
return editTextName;
}
public EditText getEditTextLastName() {
return editTextLastName;
}
public EditText getEditTextUsername() {
return editTextUsername;
}
public EditText getEditTextEmail() {
return editTextEmail;
}
}
А это мой класс ProfileController
public class ProfileController implements View.OnClickListener {
private ProfileFragment profileFragment;
private Account account;
private AccountDAO accountDAO;
private DAOFactory daoFactory;
public ProfileController(ProfileFragment profileFragment) {
this.profileFragment = profileFragment;
account = new Account(profileFragment.getEditTextName().getText().toString(),
profileFragment.getEditTextLastName().getText().toString(),
profileFragment.getEditTextUsername().getText().toString(),
profileFragment.getEditTextEmail().getText().toString(),
profileFragment.getEditTextPassword().getText().toString());
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.floating_action_button_edit_profile_fragment:
showPasswordDialog();
break;
}
}
private void showPasswordDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(profileFragment.getActivity());
LayoutInflater layoutInflater = profileFragment.requireActivity().getLayoutInflater();
final View dialogView = layoutInflater.inflate(R.layout.dialog_request_password, null);
builder.setView(dialogView)
.setPositiveButton(R.string.verify, null);
AlertDialog dialog = builder.create();
dialog.show();
setOnClickListenerDialogInsertPassword(dialog);
}
private void setOnClickListenerDialogInsertPassword(final AlertDialog dialog) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText editTextPasswordInsertedInDialog = dialog.findViewById(R.id.text_input_edit_text_password_modify_profile);
String passwordInsetedInDialog = editTextPasswordInsertedInDialog.getText().toString();
if (account.getPassword().equals(passwordInsetedInDialog)) {
dialog.dismiss();
showInsertNewPasswordDialog();
} else {
Toast.makeText(profileFragment.getContext(), "Le password non coincidono", Toast.LENGTH_SHORT).show();
}
}
});
}
private void showInsertNewPasswordDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(profileFragment.getActivity());
LayoutInflater layoutInflater = profileFragment.requireActivity().getLayoutInflater();
final View dialogView = layoutInflater.inflate(R.layout.dialog_insert_new_password, null);
builder.setView(dialogView)
.setCancelable(false)
.setPositiveButton(R.string.verify, null)
.setNegativeButton(R.string.cancel, null);
final AlertDialog dialog = builder.create();
dialog.show();
setOnClickListenerDialogInsertNewPasswordPositiveButton(dialog);
}
private void setOnClickListenerDialogInsertNewPasswordPositiveButton(final AlertDialog dialog) {
dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditText editTextNewPassword = dialog.findViewById(R.id.text_input_edit_text_insert_password);
EditText editTextRepeatNewPassword = dialog.findViewById(R.id.text_input_edit_text_repeat_password);
if (editTextNewPassword.getText().toString().equals(editTextRepeatNewPassword.getText().toString())) {
dialog.dismiss();
doUpdatePassword(editTextNewPassword.getText().toString());
} else {
Toast.makeText(profileFragment.getContext(), "Le password non coincidono", Toast.LENGTH_SHORT).show();
}
}
});
}
public void setListenersOnProfileFragment() {
profileFragment.getFloatingActionButton().setOnClickListener(this);
}
private void doUpdatePassword(String newPassword) {
daoFactory = DAOFactory.getInstance();
accountDAO = daoFactory.getAccountDAO(ConfigFileReader.getProperty("account_storage_technology",
profileFragment.requireActivity().getApplicationContext()));
if (accountDAO.updatePassword(account, profileFragment.getContext(), newPassword)) {
Toast.makeText(profileFragment.requireActivity().getApplicationContext(), "Password aggiornata", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(profileFragment.requireActivity().getApplicationContext(), "Password non aggiornata", Toast.LENGTH_LONG).show();
}
}
}
К сожалению, его макет предварительного просмотра xml предварительный просмотр сильно отличается от фактического фактического . Как вы можете видеть, в фактическом действии нет макета ввода «электронная почта», тогда как он присутствует в предварительном просмотре макета xml.
- В чем дело? Как я могу решить эту проблему?
Это сводит меня с ума. Думаю проблема во вложенности в файл xml.