DAO.class:
@Dao
public interface VisitorDAO {
@Query("Select * from visitor")
Flowable<List<Visitor>> getAll();
@Insert
Completable Insert(Visitor visitor); //Using Single or Maybe tells the Database and the mainthread that this operation will be performed on Rxjava.
@Update
public void Update(Visitor visitor);
@Delete
public void Delete(Visitor visitor);
}
代码:
@Override
public void onComplete() {
visitorFlowable = database.visitorDAO().getAll();
t.setText(visitorFlowable.); //is this the right way????
Toast.makeText(Add_Visitors.this, "Insert Successful!", Toast.LENGTH_SHORT).show();
我已将查询设置为Flowable,其想法是访问这些Flowable返回类型数据并将其显示在textview上。
答案 0 :(得分:0)
visitorFlowable = database.visitorDAO().getAll();
将返回可流动对象,您需要在UI线程上订阅它并更新textView
database.visitorDAO().getAll()
.observeOn(schedulerProviders.ui())
.subscribe(
list -> {
//list is List<Visitor>, use it to update textView
},
throwable -> {
//this block is executed if any exception is thrown
}
);