在房间数据库中需要帮助

时间:2018-12-21 11:36:07

标签: android database android-room

MyDao Class每次给我一个错误时,都没有正确响应它给我的方式,需要帮助来确定问题。即使它是来自youtube类的副本,我也检查了评论是否有什么问题,但每个人似乎都做对了。

    public class AddUserFragment extends Fragment {
    private EditText UserId,UserName,UserEmail;
    private Button Savebn;

    public AddUserFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view = inflater.inflate(R.layout.fragment_add_user, container, false);

        UserId=view.findViewById(R.id.txt_user_id);
        UserName=view.findViewById(R.id.txt_user_name);
        UserEmail=view.findViewById(R.id.txt_user_email);
        Savebn=view.findViewById(R.id.bn_save);

        Savebn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                int userid = Integer.parseInt(UserId.getText().toString());
                String username = UserName.getText().toString();
                String useremail = UserEmail.getText().toString();

                User user = new User();
                user.setId(userid);
                user.setName(username);
                user.setEmail(useremail);

                MainActivity.myAppDatabase.myDao().addUser(user);

                Toast.makeText(getActivity(),"User added successfully",Toast.LENGTH_SHORT).show();

                UserId.setText("");
                UserName.setText("");
                UserEmail.setText("");

            }
        });

        return view;
    }

   }

0 个答案:

没有答案