2016-08-16 49 views
0

解决掉的解决

问题里面有realm.copyToRealm(item);Android的境界得到不是一个交易错误

问题

更换realm.commitTransaction();当我的听众从对话中获取数据的interface并尝试保存选择数据一流的模式。我不能在表中从对话框中创建新行

获取数据:

takeUserEwalletCurrency.setOnTakeUserEwallet(new TakeUserEwalletCurrency.IOnChooseEwallet() { 
    @Override 
    public void getItem(int item) { 
     takeUserEwalletCurrency.dismissDialog(); 
     switch (item) { 
      case 1: 
       String choiceUSDUserEwallet = "SHUSD" + userPhoneNumber.substring(1, userPhoneNumber.length()); 
       updateEwalletsHistory(choiceUSDUserEwallet, "SHUSD"); 
       to_ewallet.setText(choiceUSDUserEwallet); 
       validateEnteredEwalletNumber(); 
       break; 
      case 2: 
       ... 
       break; 
     } 
    } 
}); 
takeUserEwalletCurrency.showDialog(); 

创建一个新的行:

private void updateEwalletsHistory(final String currentEwallet, final String ewalletCurrency) { 
    final EwalletsHistory exists_row = realm.where(EwalletsHistory.class).equalTo("ewalletName", currentEwallet).findFirst(); 

    if (exists_row == null) { 
     realm.executeTransaction(new Realm.Transaction() { 
      @Override 
      public void execute(Realm realm) { 
       EwalletsHistory item = new EwalletsHistory(); 
       item.setEwalletName(currentEwallet); 
       item.setEwalletCurrency(ewalletCurrency); 
       realm.commitTransaction(); 
      } 
     }); 
    } 
} 

他们都如对话界面,在表中创建新行是同样的活动

回答

1

这是因为你打电话commitTransaction()里面executeTransaction()

executeTransaction()句柄begin/commit/cancelTransaction()方法调用。

+0

是的,你没错,谢谢 –