简体   繁体   中英

Retrieving data from Sugar ORM through Shared Preference

I'm trying to create an update user info fragment on my android application. On my login page, I have asked the user to fill out his/her email and password to get into the system. Then once I get to the user info fragment I want to display all the information about the user. Therefore I have set a shared a preference to my email on my login page and I get it on my user info fragment. Now I need to figure out how to retrieve data from my database using this email. I'm using Sugar ORM. Is there any method that could let me get the data corresponding to the email address. eg: firstname, lastname etc. Unfortunately, my query below is not working.

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;
}

This is my model class for 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;
}
}

Figured it out guys !

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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