我正在尝试在我的 Android 应用程序上创建更新用户信息 fragment 。在我的登录页面上,我要求用户填写他/她的电子邮件和密码以进入系统。然后,一旦我到达用户信息 fragment ,我想显示有关用户的所有信息。因此,我在我的登录页面上设置了对我的电子邮件的共享偏好,并且我在我的用户信息 fragment 中得到了它。现在我需要弄清楚如何使用这封电子邮件从我的数据库中检索数据。我正在使用 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;
}
这是我的 sugar 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());
}
关于android - 通过 Shared Preference 从 Sugar ORM 中检索数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50431884/