【发布时间】:2020-02-08 21:54:55
【问题描述】:
我正在尝试执行一个简单的更新查询,其中将更新一行中的一列。我在网上看到的每个示例都会进行全面更新,其中更新了整行。我正在使用 MVVM - Activity、Viewmodel、Repository、AsyncTask、DAO。
在我执行异步任务之前一切正常。 doInBackground 方法需要 2 个参数,即用于标识行的主键和要更新的数据。然而,异步任务只接受对象。所以我不确定如何进行。请看下面的sn-ps:
DAO
@Query ("UPDATE CbtTable SET twistedThinkingPK = :twistedThinkingPK WHERE cbtId = :cbtId")
void updateTwistedThinking(long cbtId, long twistedThinkingPK);
ASYNC
@Override
protected Void doInBackground(CbtTable... cbtTables) {
mCbtDao.updateTwistedThinking(cbtTables[0]); // THIS THROWS THE ERROR, IT WANTS THE TWO VARIABLES FORM THE DAO UPDATE QUERY.
return null;
REPOSITORY
public void updateTwistedThinking(CbtTable cbtTable){
new UpdateTwistedThinkingAsyncTask(cbtDao).execute(cbtTable);
}
VIEW MODEL
public void updateTwistedThinking(CbtTable cbtTable){
cbtRepository.updateTwistedThinking(cbtTable);
}
ACTIVITY
public void updateTwistedThinkingCbtTable(long twistedThinkingPK){
CbtTable cbtTable = new CbtTable();
cbtTable.setTwistedThinkingPK(twistedThinkingPK);
cbtViewModel.updateTwistedThinking(cbtTable);
}
【问题讨论】:
标签: android mvvm android-asynctask android-sqlite android-room