Feb 13 | 7:20 PM |
Mark M. | has entered the room |
Feb 13 | 7:25 PM |
Mark M. | turned on guest access |
Feb 13 | 7:50 PM |
Uno T. | has entered the room |
Mark M. |
hello, Uno!
|
Mark M. |
how can I help you today?
|
Uno T. |
View paste
|
Mark M. |
onListItemClick() is available to you in ListActivity and ListFragment
|
Mark M. |
if you extend either of those classes, you can override onListItemClick()
|
Uno T. |
ini ListFragment
|
Mark M. |
to find the item, call getItem() on your Adapter, passing in the position
|
Mark M. |
for a SimpleCursorAdapter, the return value of getItem() will be your Cursor, positioned at the proper row
|
Mark M. |
you can then call methods on the Cursor like getString() and getInt() to retrieve values for columns out of that row
|
Mark M. |
ViewHolder has nothing to do with onListItemClick(), generally speaking
|
Mark M. |
if you have another question, go right ahead
|
Uno T. |
the _id from SimpleCursorAdapter is mapped to long id or int position in onListItemClick view ?
|
Feb 13 | 7:55 PM |
Mark M. |
the _id is passed to you as the long id parameter in onListItemClick()
|
Uno T. |
ok great.
|
Uno T. |
you mean like this:
|
Uno T. |
View paste
|
Mark M. |
no
|
Mark M. |
getItem() takes the position, not the id
|
Mark M. |
and getItem() is a method on your SimpleCursorAdapter, not on ListFragment
|
Mark M. |
Cursor cr=(CursorAdapter)getListAdapter().getItem(position)
|
Feb 13 | 8:00 PM |
Uno T. |
ok... great
|
Uno T. |
other question:
|
Uno T. |
I implement this code :
|
Uno T. |
View paste
|
Uno T. |
and run on simulator
|
Feb 13 | 8:05 PM |
Uno T. |
when it's called because i switch the fragment then go back to that fragment. It's got an error : attempt to re-open an already-closed object sqlitequery
|
Mark M. |
how are you getting the Cursor in the first place?
|
Uno T. |
in onActivityCreated using AsyncTask: new LoadCursorTask().execute();
|
Mark M. |
"because i switch the fragment then go back to that fragment" -- what do you mean?
|
Feb 13 | 8:10 PM |
Uno T. |
i mean there are two fragments, I move one to another by using Navigation Drawer
|
Mark M. |
how are you doing this? by a FragmentTransaction?
|
Uno T. |
in MainActivity:
|
Uno T. |
View paste
|
Mark M. |
are you creating a new instance of your ListFragment when you return to it? or are you running another replace() transaction to put the prior fragment instance back on the screen?
|
Feb 13 | 8:15 PM |
Uno T. |
hmm.. i think it's just replaced. because there is checking if (members==null) before creating it.
|
Mark M. |
it feels like that you are holding onto something in your fragment that is associated with the old Cursor and SQLiteDatabase
|
Mark M. |
however, the stack trace should point you to it
|
Mark M. |
either clean that up, so it is re-initialized when your fragment is re-created, or switch to using detach() and attach() instead of replace()
|
Mark M. | |
Uno T. |
ok
|
Uno T. |
will try to dig it more
|
Feb 13 | 8:30 PM |
Mark M. |
that's a wrap for today's chat
|
Mark M. |
the transcript will be posted shortly to http://commonsware.com/office-hours/
|
Mark M. |
the next chat is tomorrow, 10am US Eastern Time
|
Mark M. |
have a pleasant day!
|
Uno T. | has left the room |
Mark M. | turned off guest access |