android-room

LiveData Object keeps being null after getValue() is called

╄→гoц情女王★ 提交于 2020-04-10 09:19:34
问题 I want to update a member variable of an object inside my Repository on a LiveData- Object. The problem is, that if I call the getValue() Method, I keep getting an NullPointerException, although the value does exist inside my Room- Library. My question now is, how do I get the value from the LiveData Object without calling the observe() Method? (I am not able to call the observe method inside my repository, cause that method wants me to enter a LifeCycleOwner- reference, which is not present

LiveData Object keeps being null after getValue() is called

不羁的心 提交于 2020-04-10 09:16:20
问题 I want to update a member variable of an object inside my Repository on a LiveData- Object. The problem is, that if I call the getValue() Method, I keep getting an NullPointerException, although the value does exist inside my Room- Library. My question now is, how do I get the value from the LiveData Object without calling the observe() Method? (I am not able to call the observe method inside my repository, cause that method wants me to enter a LifeCycleOwner- reference, which is not present

How to implement created_at and updated_at column using Room Persistence ORM tools in android

谁都会走 提交于 2020-04-10 07:32:22
问题 How can I implement created_at and updated_at columns using Room Persistence ORM tools in Android, that can update the timestamp automatically when creating or updating a row in a table? 回答1: I've research many sites, but still not found any results can handle middleware or something like callbacks when we Query , Insert , Update , or Delete ,... methods from DAO s. As @selvin said, RoomDatabase.Callback interface only call when database created in first time. So, use that interface is

Kotlin - return new inserted id from Room database using Persistence Room:runtime lib

二次信任 提交于 2020-04-10 03:55:14
问题 I am trying to insert user record in Room database using Kotlin and It's working perfectly. And now I want to return newly inserted record id to check if a record is successfully inserted or not in Room database. But when I am applying Long return type in the insert method and run the code that time I get the following error. error: Method returns long but it should return one of the following: void, long[], java.lang.Long[], java.util.List<java.lang.Long> . If you want to return the list of

Kotlin - return new inserted id from Room database using Persistence Room:runtime lib

不打扰是莪最后的温柔 提交于 2020-04-10 03:54:10
问题 I am trying to insert user record in Room database using Kotlin and It's working perfectly. And now I want to return newly inserted record id to check if a record is successfully inserted or not in Room database. But when I am applying Long return type in the insert method and run the code that time I get the following error. error: Method returns long but it should return one of the following: void, long[], java.lang.Long[], java.util.List<java.lang.Long> . If you want to return the list of

how can fillter the recyclerView

无人久伴 提交于 2020-04-05 06:58:45
问题 how can i filter Recycler View using SearchView i try all the video tuturial but all of them get thier item Recycler View from a list but i get my item from db and dont know how should i do this this is my adapter Code public class AthleteAdapter extends RecyclerView.Adapter<AthleteAdapter.AthleteHolder> { private List<Athlete> athletes = new ArrayList<>(); private OnItemClickListener listener; @NonNull @Override public AthleteHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType)

How to display Flowable data on a Textview in Room Database using Rxjava2

拜拜、爱过 提交于 2020-03-25 16:06:30
问题 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); } Code: @Override public void onComplete() { visitorFlowable = database.visitorDAO().getAll(); t.setText(visitorFlowable.); //is this the

How can I turn a list of strings into LIKE clauses in a Room Query?

狂风中的少年 提交于 2020-03-25 16:04:54
问题 I have a table called games that has a column called platforms , which contains a list of platform abbreviations. This is a list of all the platforms that specific game came out on. Here's an example of one of the cells in platforms : AMI,GG,SNES,CPC,AST,C64,SPEC,MAC,PS2,NES,3DO,ARC,XBGS,PS3N,PC,IPHN,DSI,HALC,PSPN,ANDR, The user can choose any number of platforms they wish to view games for. For example, they may choose to see games for the following platforms: SNES, MAC, PC So I need a way

How can I turn a list of strings into LIKE clauses in a Room Query?

ぐ巨炮叔叔 提交于 2020-03-25 16:04:26
问题 I have a table called games that has a column called platforms , which contains a list of platform abbreviations. This is a list of all the platforms that specific game came out on. Here's an example of one of the cells in platforms : AMI,GG,SNES,CPC,AST,C64,SPEC,MAC,PS2,NES,3DO,ARC,XBGS,PS3N,PC,IPHN,DSI,HALC,PSPN,ANDR, The user can choose any number of platforms they wish to view games for. For example, they may choose to see games for the following platforms: SNES, MAC, PC So I need a way

android left join query with room

感情迁移 提交于 2020-03-22 08:16:23
问题 I am trying to change my sqlite database with room library. I am little confuse with left join query. I have implemented it with sqlite, but don't know how can I achieve same withh room? Here is my table creation: first table: Notification db.execSQL("CREATE TABLE IF NOT EXISTS $TABLE_NAME ($COLUMN_ID INTEGER PRIMARY KEY, $ICON TEXT, $TITLE INTEGER," + " $DATE INTEGER, $TYPE INTEGER,$URL TEXT, $MESSAGE INTEGER, FOREIGN KEY($TITLE) REFERENCES ${TableNotificationsTrans.getTableName(this)}(id),"