android


How to query on current date and bring back objects in Realm that contains it?


So working on a android app using the realm database. I can find out the current date, which I can do using Calendar.getInstance(), but what I want to know is how I can use a realm model to actually store different weekdays for a object.
My model looks like this:
public class Habit extends RealmObject{
private static int id=0;
private String name;
private Date created;
private ArrayList<Date> repeat;
private Date updated;
private Date reminder;
private int target;
private int tracker;
// getter and setters
}
I am trying to store the days that would be repeating (so max 7 or daily, and at least 1 as minimum) in the ArrayList of repeat since Realm doesn't accept Calendar.
I would create the object and then pass in the appropriate data to fill in the fields and based on the number of days selected send those date objects as well (for example Repeat on Monday, Tuesday, Friday). I would then query on the realm db to bring back all objects that contain the current date gotten by the calendar.getInstance(). At least this is what I was thinking.
The problem however is that at the moment I am taking a string input to determine which days the user wants the item to repeat, how do i translate this to a date item that is the weekday/weekend and then store it in my realm object?
Any help or suggestions would really help in getting this to work. Also if any extra code would help let me know what I can add.
Thank you.
private ArrayList<Date> repeat;
Realm does not support list of primitives, and Date is considered a primitive.
You need to create a class-specific object that has a Date parameter.
public class Habit extends RealmObject{
private static int id=0;
private String name;
private Date created;
private RealmList<HabitDate> repeat;
private Date updated;
private Date reminder;
private int target;
private int tracker;
// getter and setters
}
public class HabitDate extends RealmObject {
private Date date;
private Habit habit; // <-- because query across `#LinkingObjects` is 3.3+
}

Related Links

Android alpha testing “Item not found”
Retrieving images using its path from server to android app
RecyclerView notifyItemChanged Prevent Scroll [duplicate]
Google Analytics doesn't report Real-time Android
Edit text integer
Titanium Alloy crash on android, Cannot call method 'open' of undefined
Native components, armeabi-v7a, and thumb?
Checkbox getting deselected in arrayadapter in listview
Android: member variable becoming null
How to detect color of the center of camera streaming in android without OpenCV
Missing App Icon after modifying Manifest
Save Image from res/drawable to Image Gallery Android
SQL lite select for actual week (from monday till sunday)
how to get imageview height and width after pinch zoom?
How to properly create a customized animated drawable?
Android Backstack Management

Categories

HOME
phantom-dsl
cobalt
android-studio-2.2
alexa-skills-kit
camera
hessian
saml-2.0
jsf-2.2
cakephp-3.4
telegram-bot
jetty
crystal-reports-2013
trac
boto3
elasticsearch-5
ipmitool
tput
libc
onedrive-api
cumulocity
azure-iot-hub
imessage
ag
tosca
mount
syntax-highlighting
ms-access-web-app
has-and-belongs-to-many
tpm
iis-express
tizen-tv
dst
jbutton
android-gridview
github3.py
keras-layer
carriage-return
wurfl
openalpr
odroid
resolution
branching-and-merging
vaadin-charts
magic-draw
colorbar
css-transforms
javafx-css
visual-studio-2008-sp1
meteor-packages
file-uri
bizagi
pushbots
user-management
asyncdisplaykit
roadkill-wiki
poppler
page.js
mass-assignment
teaspoon
genymotion-call
insight.database
grails-domain-class
jjaql
android-framework
menubar
getopt
solace-mq
rolify
time.h
jquery-1.9
wp7test
sqlclr
resource-management
monotouch.dialog
xcode3.2
dajaxice
adobe-media-server
procedures
ikimagebrowserview
role
multiplatform
django-paypal
nhprof
strtod
localizable.strings
sqlobject
unmanagedresources
change-management
pbcopy
blind

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App