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

Close navigation drawer in Android by tapping on the empty portion of the screen
CursorAdapter updating the list in a wierd manner
Changing views layout parameters on runtime
Transfer data from android framework to app
Android navigation drawer trigger area is too small
Android Load higher resolution image from local drawable-nodpi and zoom
Issue adding a callback for a surfaceview - Android
ACTION_LOCATION_SOURCE_SETTINGS : cannot be resolved or is not a field
Android Retrofit GET request ConversionException issue
Run start service when application starts and run across multiple activities
Google Analytics (GA) send call with simple params on Android don't show results in dashboard
ArrayAdapter text and image
Android SQLite - Primary Key - Inserting into table
Generate High frequency sound on android
Not enough space to show ad (AdMob)
EasyTracker does not perform auto-tracking

Categories

HOME
batch-file
windows
uml
phantom-dsl
phpword
turing-machines
codenvy
telegram
package
scripting
permissions
data-visualization
gluon-mobile
boto3
extjs4.2
opengl-es-3.0
3nf
foreign-keys
production
sse
boost-icl
pagespeed
imageresizer
epsilon
xunit
draft-js-plugins
bulletphysics
jasmine-node
fractions
intersystems-cache
bringtofront
iis-express
jaws
autodesk-designautomation
xbox
left-join
kodi
fstream
papaparse
mailkit
card.io
android-maps-extensions
activexobject
getpixel
navigator
lint
timing
modernizr
filesystemwatcher
dbnull
memory-mapping
jide
openal
proget
wcftestclient
yii2-api
dtsearch
trojan
magic-draw
excel-dna
pdf-conversion
oozie-coordinator
shinobi
myspace
gogs
avspeechsynthesizer
refinerycms
android-wake-lock
boost-serialization
invoke-sqlcmd
qbxml
atan2
xenomai
video-player
android-launcher
extjs-grid
keyup
canvg
google-refine
entity-framework-4.3
zend-currency
j-security-check
broadband
exceldatareader
beatsmusic
boost-program-options
pseudo-class
lnk
matrix-inverse
jjaql
winginx
spring-remoting
koala
gwt-openlayers
light
gtm-oauth2
beaker-testing
neos-server
nebula
flex++
actiondispatch
android-sdk-2.3
android-loadermanager
subproject
database-create
wiimote
tournament
event-receiver
quotation-marks
mtu
presentation-layer
office-2007
request-headers
wcf-instancing
fdf

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