繁体   English   中英

通过共享首选项从Sugar ORM检索数据

[英]Retrieving data from Sugar ORM through Shared Preference

我正在尝试在我的android应用程序上创建一个更新用户信息片段。 在我的登录页面上,我已要求用户填写他/她的电子邮件和密码以进入系统。 然后,一旦到达用户信息片段,我想显示有关该用户的所有信息。 因此,我在登录页面上为我的电子邮件设置了共享首选项,并在用户信息片段中得到了它。 现在,我需要弄清楚如何使用此电子邮件从数据库中检索数据。 我正在使用Sugar ORM。 有什么方法可以让我获取与电子邮件地址相对应的数据。 例如:名,姓等。不幸的是,我的以下查询无法正常工作。

SharedPreferences sharedpreferences;
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
   View rootView= inflater.inflate(R.layout.profile, container, false);
   TextView emailLabel=(TextView) rootView.findViewById(R.id.textView3);
    TextView nameLabel=(TextView) rootView.findViewById(R.id.textView4);
    sharedpreferences = getContext().getSharedPreferences(MyPREFERENCES, Context.MODE_PRIVATE);
    String email=sharedpreferences.getString(Email,"");
    List<User>user_email=User.findWithQuery(User.class,"SELECT * from USER WHERE email = ?",email);
    emailLabel.setText(email);
    nameLabel.setText(user_email);

    return rootView;
}

这是我的糖ORM模型班

public class User extends SugarRecord<User> {
String fistname;
String lastname;
String email;
String password;
String confirmpassword;

public User() {
}

public User(String fistname, String lastname, String email, String password, String confirmpassword) {
    this.fistname = fistname;
    this.lastname = lastname;
    this.email = email;
    this.password = password;
    this.confirmpassword = confirmpassword;
}
}

弄清楚了伙计们!

    List<User> user = User.findWithQuery(User.class,"SELECT * FROM USER WHERE email = ?",email);
    for (User users:user){
        nameLabel.setText(users.getFistname().toString());
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM