May 30 | 7:00 PM |
Mark M. | has entered the room |
May 30 | 7:20 PM |
Mark M. | turned on guest access |
May 30 | 7:45 PM |
Carlos | has entered the room |
May 30 | 7:50 PM |
Carlos |
Hi Mark!
|
May 30 | 7:50 PM |
Mark M. |
hello, Carlos!
|
Mark M. |
how can I help you today?
|
Carlos |
I feel embarrassed asking this question, but oohhh well...
|
Carlos |
has to do with notifications and removal of listview items
|
Carlos |
I'm setting reminders through AlarmManager for items in a ListView.
|
Carlos |
I'm passing around the bundle/intent through my activities, including my Schedule service that creates the notification.
|
Carlos |
IN that intent I'm also including the position of the item in the list view /adapter
|
Mark M. |
what is "the bundle/intent"?
|
Carlos |
by bundle/intent I mean when passing data between activities/fragments I add the selected item data as an intent
|
Mark M. |
OK
|
Carlos |
Then for creating the notification, the schedule
service uses that intent data that includes all the info for the
specific item in the listview
|
Carlos |
The problem that I'm having is that, because I
include the item's list position in the intent, if another item gets
deleted from the listview, the list position sent to alarmmanager (and
received by the notification) is no longer valid
|
Mark M. |
um
|
Mark M. |
let's roll back a bit
|
Carlos |
Something very basic and obvious I'm missing in my
implementation so that the data sent to the notification is not tied to
the list position.
|
Mark M. |
I have serious reservations about: "I'm setting reminders through AlarmManager for items in a ListView"
|
Carlos |
ok
|
Mark M. |
aren't you setting reminders through AlarmManager for items in a database?
|
Carlos |
Basically I'm doing a todo type of app
|
May 30 | 7:55 PM |
Carlos |
User selects a specific item, sets the reminder, etc
|
Carlos |
Through my app code I sent to AlarmManager all the data model for the specific item/task
|
Carlos |
This includes the position of the item in the list
|
Mark M. |
ignore the ListView
|
Mark M. |
where are you *really* storing your items? a database? a file? on the Internet? something else?
|
Carlos |
I have them both in my Application object and in the sqlite db
|
Mark M. |
great
|
Mark M. |
so, in your database, you have a primary key for your todo list items, right?
|
Carlos |
Yes, an id of type long
|
Mark M. |
*that's* your todo identifier, then, throughout your app
|
Mark M. |
positions in a ListView are meaningless; primary keys are not
|
Carlos |
At some point I was brainstorming on that, but my next question is...
|
Carlos |
Once I retrieved the data for the specific
item/task from the database (through the primary key) how to I connect
that to my arrayadapter in case the user wants to do edits to the item?
How do I use the primary key to retrieve where in the list is the item?
|
Mark M. |
your ArrayAdapter is presumably an ArrayAdapter<ToDoItem>, or something along those lines
|
May 30 | 8:00 PM |
Mark M. |
ToDoItem should know its primary key
|
Carlos |
I check the arrayadapter methods and was unable to find one that would let me send a custom object
|
Mark M. |
I have no idea what you mean by "send a custom object"
|
Carlos |
Yes Mark that's is correct
|
Mark M. |
your Application object, in theory, could hold a HashMap<Long, ToDoItem> as your in-memory cache
|
Carlos |
Are you saying that I should modify my getView() method to use the primary key?
|
Mark M. |
that allows you to get the ToDoItem for a given primary key
|
Mark M. |
from there, getPosition() on ArrayAdapter will give you the position in the list, should you need it
|
Carlos |
In my data models for the ToDo I also store the primary key, so in that case I wouldn't need the hash. I can do todo.getId()
|
Mark M. |
or, in the reverse, when the user clicks on an
item in the list, you know the ToDoItem via its position, and from there
you know its primary key
|
Mark M. |
the HashMap is to find the cached model object given the key
|
Mark M. |
perhaps you won't need that
|
Mark M. |
but I suspect that you will
|
Carlos |
so the way I would use get position is something like this: int position = getPosition(ToDOItem) ????
|
Mark M. |
correct
|
Carlos |
Hmmm. /facepalm
|
Carlos |
Don't know how I missed that method
|
May 30 | 8:05 PM |
Carlos |
I don't have to implement that method myself with @Override, right?
|
Mark M. |
no
|
Mark M. |
it just calls indexOf() on the underlying ArrayList
|
Mark M. | |
Mark M. |
lines 347-349
|
Carlos |
Just so that. Awesome. Thanks for your help Mark! That was my only question for today!
|
Mark M. |
I'm happy to be useful!
|
Carlos |
Have a good evening! Bye!
|
Carlos | has left the room |
May 30 | 8:30 PM |
Mark M. | turned off guest access |