输入被更新为数据库中的错误字段

蜡烛

我已经完成了编码,我想更新配置文件。但是用户输入的输入被放置在数据库内的错误字段中。我不知道什么时候出错了。

性别显示电话号码,电话号码显示“性别”如何解决?

这是更新功能。

private void showUpdateDialog(String phoneNumber) {


        //init dialog
        bottomSheetDialog = new BottomSheetDialog(this);
        bottomSheetDialog.setTitle("one more step!");
        bottomSheetDialog.setCanceledOnTouchOutside(false);
        bottomSheetDialog.setCancelable(false);
        View sheetView = getLayoutInflater().inflate(R.layout.layout_update_information, null);

        Button btn_update = sheetView.findViewById(R.id.btn_update);
        TextInputEditText edt_name = sheetView.findViewById(R.id.edt_name);
        TextInputEditText edt_email = sheetView.findViewById(R.id.edt_email);
        TextInputEditText edt_address = sheetView.findViewById(R.id.edt_address);
        TextInputEditText edt_gender = sheetView.findViewById(R.id.edt_gender);

        btn_update.setOnClickListener(view -> {

            if (!dialog.isShowing())
                dialog.dismiss();

            User user = new User(edt_name.getText().toString(),
                    edt_email.getText().toString(),
                    edt_address.getText().toString(),
                    edt_gender.getText().toString(),
                    phoneNumber);
            userRef.document(phoneNumber)
                    .set(user)
                    .addOnSuccessListener(aVoid -> {
                        bottomSheetDialog.dismiss();
                        if (dialog.isShowing())
                            dialog.dismiss();
                        Toast.makeText(HomeActivity.this, " Thank You", Toast.LENGTH_SHORT).show();
                    }).addOnFailureListener(e -> {
                if (dialog.isShowing())
                    dialog.dismiss();
                bottomSheetDialog.dismiss();
                Toast.makeText(HomeActivity.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
            });

        });

        bottomSheetDialog.setContentView(sheetView);
        bottomSheetDialog.show();

    }

更新布局信息

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:orientation="vertical"
    android:padding="8dp">



    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edt_name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="Your name" />
    </com.google.android.material.textfield.TextInputLayout>



    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edt_email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="Your email" />
    </com.google.android.material.textfield.TextInputLayout>


    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edt_address"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="Your address" />
    </com.google.android.material.textfield.TextInputLayout>


    <com.google.android.material.textfield.TextInputLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/edt_gender"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:inputType="text"
            android:hint="Your gender" />
    </com.google.android.material.textfield.TextInputLayout>


    <Button
        android:id="@+id/btn_update"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/txt_skip"
        android:background="@drawable/button"
        android:text="Update Profile" />

</LinearLayout>

用户.java

public class User {
    private String name,email,address,phoneNumber,gender;

    public User(){

    }

    public User(String name, String email, String address, String phoneNumber, String gender){
        this.name= name;
        this.email=email;
        this.address=address;
        this.phoneNumber=phoneNumber;
        this.gender=gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhoneNumber() {
        return phoneNumber;
    }

    public void setPhoneNumber(String phoneNumber) {
        this.phoneNumber = phoneNumber;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }
}
康斯坦丁啤酒

您只需在填充用户时在代码中输入错误的顺序即可。正如在您的User类中所见,您的构造函数采用as 参数phoneNumber之前的gender参数。但在你new User(...)初始化你把edt_gender.getText().toString()之前phoneNumber

像这样改变你的代码:

void showUpdateDialog(String phoneNumber) {


        //init dialog
        bottomSheetDialog = new BottomSheetDialog(this);
        bottomSheetDialog.setTitle("one more step!");
        bottomSheetDialog.setCanceledOnTouchOutside(false);
        bottomSheetDialog.setCancelable(false);
        View sheetView = getLayoutInflater().inflate(R.layout.layout_update_information, null);

        Button btn_update = sheetView.findViewById(R.id.btn_update);
        TextInputEditText edt_name = sheetView.findViewById(R.id.edt_name);
        TextInputEditText edt_email = sheetView.findViewById(R.id.edt_email);
        TextInputEditText edt_address = sheetView.findViewById(R.id.edt_address);
        TextInputEditText edt_gender = sheetView.findViewById(R.id.edt_gender);

        btn_update.setOnClickListener(view -> {

            if (!dialog.isShowing())
                dialog.dismiss();

            User user = new User(edt_name.getText().toString(),
                    edt_email.getText().toString(),
                    edt_address.getText().toString(),
                    phoneNumber,
                    edt_gender.getText().toString(),
                    );
            userRef.document(phoneNumber)
                    .set(user)
                    .addOnSuccessListener(aVoid -> {
                        bottomSheetDialog.dismiss();
                        if (dialog.isShowing())
                            dialog.dismiss();
                        Toast.makeText(HomeActivity.this, " Thank You", Toast.LENGTH_SHORT).show();
                    }).addOnFailureListener(e -> {
                if (dialog.isShowing())
                    dialog.dismiss();
                bottomSheetDialog.dismiss();
                Toast.makeText(HomeActivity.this, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
            });

        });

        bottomSheetDialog.setContentView(sheetView);
        bottomSheetDialog.show();

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

Asp.net表单将数据插入数据库中的错误字段

来自分类Dev

输入字段未在数据库中更新

来自分类Dev

将数据库迁移到新服务器时,MySQL 错误字段列表中的未知列 (Windows)

来自分类Dev

无法更新数据库中的字段

来自分类Dev

Jackcess:MSAccess 数据库的错误字符集

来自分类Dev

使用数据库中动态创建的输入字段更新mysql中的表

来自分类Dev

在输入字段上按Enter键以更新数据库

来自分类Dev

将文本框输入值设置为数据库中的字段?

来自分类Dev

PHP在输入字段中获取数据库数据

来自分类Dev

更新查询只使数据库表字段为空

来自分类Dev

for循环将正确的文本字段更新为数据库中的正确列(解析)

来自分类Dev

为数据库表中的重复输入或输出生成错误消息

来自分类Dev

数据库输入错误

来自分类Dev

使用隐藏字段更新数据库中的数据

来自分类Dev

输入字段在Rails数据库中显示nil

来自分类Dev

获取数据库输出以显示在输入字段中

来自分类Dev

PHP在数据库中添加输入字段值

来自分类Dev

Spring Boot中的数据库字段为空的问题

来自分类Dev

MySQL数据库字段PHP中的Textarea为空

来自分类Dev

更新数据库错误

来自分类Dev

更新数据库中的所有DATETIME字段

来自分类Dev

如何更新数据库中的多个字段

来自分类Dev

更新数据库中的个人字段

来自分类Dev

无法使用SWIFT更新数据库FMDB中的字段

来自分类Dev

更新数据库中的字段并修改其长度

来自分类Dev

Hibernate应该只更新数据库中的某些字段

来自分类Dev

更新数据库中的个人字段

来自分类Dev

更新数据库中的所有DATETIME字段

来自分类Dev

无法更新表单字段中的数据库条目

Related 相关文章

热门标签

归档