I am working on Android Room Persistent library. I have also implemented Two-way data binding in my project. In the project, I am inserting users by filling a form and displaying all the users in rows and updating them by clicking particular user row. Below is my UserDao Class:
@Dao
public interface UserDao {
@Query("SELECT * FROM user")
List<User> getAllUsers();
@Insert
void insertAll(User... users);
@Update
void updateUser(User... users);
@Query("SELECT * FROM user WHERE user_id IN (:userId)")
User getSpecifiedUser(int...userId);
}
For databinding I am binding User Model in UserFormActivity
binding.setUserModel(userModel);
Now, as Room persistent library doesn't allow you to do any database operation in Main thread, for updating the user, I am getting data of particular user in User Form by clicking in the row in new Thread as below:
private void getUserFormData(final int userId) {
try {
Thread t = new Thread(new Runnable() {
public void run() {
userModel = db.userDao().getSpecifiedUser(userId);
}
}, "Thread A");
t.start();
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
After getting data of user in userModel for updating, I want the User data to reflect in User Form where data binding is performed, but it's not reflecting. I am stuck with this issue.