[英]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.