大佬教程收集整理的这篇文章主要介绍了android – Room Invalidation tracker初始化两次,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我在Logcat中得到的:@H_@L_262_5@_4@
在onCreate中初始化数据库.@H_@L_262_5@_4@
db = Room.databaseBuilder(getApplicationContext(),ApPDAtabase.class,db_name) .fallBACkToDestructiveMigration() .allowMainThreadQueries() .build();
RecyclerView适配器代码.@H_@L_262_5@_4@
@Override public Boolean onItemMove(int fromPosition,int toPosition) { String name = dataSet.get(fromPosition).getName(); //this will make "Add item" do not move from its first position.. if (Build.VERSION.SDK_INT >= Build.VERSION_CODEs.KITKAT) { if (!(Objects.equals(name,"Add") || (toPosition == 0 && fromPosition == 1))) { Collections.swap(dataSet,fromPosition,toPosition); MoveItem(fromPosition,toPosition); notifyItemMoved(fromPosition,toPosition); return true; } } return false; }
public static void MoveItem(int fromPosition,int toPosition){ String name = data.get(fromPosition).getName(); //This gets the current item name in the view String nexName = data.get(toPosition).getName(); //This gets the next item name in the view ContentValues fromContentValues = new ContentValues(); fromContentValues.put("posItem",toPosition); //adding data to ContentValues ContentValues toContentValues = new ContentValues(); toContentValues.put("posItem",fromPosition); Log.e("Item moved",name + "from" + fromPosition + "\n" + "next item:" + "to" + toPosition); db.begintransaction(); try { db.getOpenHelper().getWritableDatabase().update(name,fromContentValues,"posItem =" + fromPosition,null); db.getOpenHelper().getWritableDatabase().update(nexName,toContentValues,"posItem =" + toPosition,null); db.settransactionsuccessful(); //setTing transaction successful } finally { db.endtransaction(); // commit or rollBACk db.close(); //closing database } }
以上是大佬教程为你收集整理的android – Room Invalidation tracker初始化两次全部内容,希望文章能够帮你解决android – Room Invalidation tracker初始化两次所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。