Mar 21 | 7:20 PM |
Mark M. | has entered the room |
Mark M. | turned on guest access |
Mar 21 | 7:25 PM |
Kevin M. | has entered the room |
Mark M. |
howdy Kevin!
|
Kevin M. |
Hi there
|
Mark M. |
how can I help you today?
|
Kevin M. |
I'm having problems with Fragments, ActionBarSherlock and menus
|
Gabriele | has entered the room |
Kevin M. |
I can't get menus to show for the 2nd fragment
|
Gabriele |
hello :)
|
Mark M. |
(howdy, Gabriele -- I will be with you shortly!)
|
Mark M. |
Kevin: do you mean that both fragments are on the screen at the same time?
|
Mar 21 | 7:30 PM |
Kevin M. |
No, I do a replace transaction. It's a pretty simple app but the menu seems to disappear.
|
Kevin M. |
I can click on the menu and it seems to do something but doesn't show
|
Mark M. |
"but doesn't show"... show what?
|
Kevin M. |
Doesn't show the text
|
Mark M. |
"show the text"... what text?
|
Kevin M. |
Menu text. No icon
|
Kevin M. |
Just 1 menu item
|
Mark M. |
what is your android:minSdkVersion?
|
Kevin M. |
I've tried about every combination. Handling everything in the activity etc
|
Kevin M. | |
Mark M. |
and what OS version are you testing this on?
|
Kevin M. |
Mostly 4.1
|
Mark M. |
are you pressing the device/emulator MENU button, or the ... affordance in the action bar?
|
Kevin M. |
I'm doing this mostly on real phones. I have done it in the emulator but get the same results
|
Mark M. |
when you "click on the menu", are you pressing the device/emulator MENU button, or the ... affordance in the action bar?
|
Kevin M. |
I don't have a submenu. Just :
|
Kevin M. |
View paste
|
Mar 21 | 7:35 PM |
Kevin M. |
so I don't see ... On the first fragment I see "New"
|
Mark M. |
I will ask this one more time
|
Mark M. |
View paste
|
Kevin M. |
I'm not pressing anything. The menu just shows up
on the first fragment. I can press that menu but other fragments don't
show a menu item
|
Mark M. |
earlier in this chat, you wrote: "I can click on the menu and it seems to do something but doesn't show"
|
Mark M. |
I have no idea what this means to you
|
Kevin M. |
This is for the ActionBar
|
Kevin M. |
So on the far right I have a menu item that is
just text that says "New". On the next screen/fragment, I want to use
another menu, say "Edit"
|
Mark M. |
when you say "menu", are you referring to the <item> from your bit of XML above?
|
Kevin M. |
Yes
|
Mark M. |
that is not a "menu"
|
Mark M. |
it is an action bar item
|
Kevin M. |
Ok, but you use menu code
|
Mar 21 | 7:40 PM |
Kevin M. |
Can I send a screenshot?
|
Mark M. |
feel free to upload one
|
Mark M. |
in the meantime, let me take a question from Gabriele
|
Mark M. |
Gabriele: do you have a question?
|
Gabriele |
I'd like to provide a small guide for my app to
users, is there some guidelines/layout/library/example to do it or from I
can get the idea?
|
Kevin M. | |
Mark M. |
Gabriele: by "small guide for my app", what do you mean? online help? something else"?
|
Gabriele |
yes, offline help, or something like this
|
Mark M. |
I think using a WebView is fairly conventional
|
Mark M. |
put your HTML/CSS/images in assets/
|
Mark M. |
use file:///android_asset/... as the URL with the WebView
|
Gabriele |
ok, I've understand, thank you
|
Mark M. |
richly formatted, can link to additional online resources, etc.
|
Mark M. |
OK, back to Kevin
|
Mark M. |
Kevin: is your screenshot showing your activity with the first fragment, or with the second fragment?
|
Kevin M. |
Does the "New" above make sense?
|
Kevin M. |
First fragment
|
Mark M. |
OK
|
Kevin M. |
When I click on a name, I replace that fragment with a new one
|
Mark M. |
OK
|
Kevin M. |
that's when the menu disappears
|
Mark M. |
well, the New entry should go away, if you defined that in the first fragment's onCreateOptionsMenu()
|
Mark M. |
the action bar will then have anything you
declared in the activity's onCreateOptionsMenu() and the second
fragment's onCreateOptionsMenu()
|
Mar 21 | 7:45 PM |
Kevin M. |
Right, but the other fragment has their own menu who's code gets called but not shown
|
Mark M. |
did you call setHasOptionsMenu(true) on the second fragment?
|
Kevin M. |
I can debug it and see that the code is being called
|
Kevin M. |
Yes
|
Gabriele |
thank you Mark, see you the next time, have a good day, Kevin too. :)
|
Mark M. |
can you paste in your onCreateOptionsMenu() method from the second fragment?
|
Kevin M. |
You too
|
Mark M. |
Gabriele: see you later!
|
Kevin M. |
View paste
|
Mark M. |
why are you calling clear()?
|
Kevin M. |
I was getting that method called several times
|
Mark M. |
then you have other problems, perhaps
|
Mark M. |
you should only need the inflate() call
|
Mark M. |
the setVisible() should crash, as you do not have
R.id.newItem, assuming that the XML you pasted earlier is from
R.menu.edit_menu
|
Kevin M. |
Yeah, that's commented out. I was trying to have 1 menu with 3 items that I would try and enable just 1
|
Mark M. |
oh, sorry, didn't realize that was a word-wrap issue -- I thought the comment was on a blank line
|
Mar 21 | 7:50 PM |
Kevin M. |
It's possible the problem was that when I called setVisible(true) that caused a problem as initially all items where not visible
|
Mark M. |
if I recall correctly, the EmPubLite sample shows
action bar items coming and going based on fragments being added and
removed from the screen, in Tutorial 19
|
Mark M. |
I also have a recent sample showing action bar
items coming and going related to pages in a ViewPager, though that is
probably less relevant here
|
Kevin M. |
ok. I'll take a look at it
|
Mark M. |
your "I was getting that method called several
times" suggests that you have some other issues, such as perhaps having
the fragment added more than once
|
Kevin M. |
I stared with a ViewPager and that didn't work too well. Got very complicated
|
Kevin M. |
I was trying to call transaction.add() before I changed to replace
|
Mark M. |
add() would not be suitable for your situation --
that would be if you wanted both the list and the second fragment on the
screen at once
|
Mark M. |
beyond that, there is little that I can suggest to
you, other than to create a sample project that reproduces problem, and
come back sometime with that project that I can take a look at
|
Prasanna P. | has entered the room |
Mark M. |
or, post that project as part of a question on StackOverflow
|
Kevin M. |
Ok. Thanks
|
Mark M. |
howdy, Prasanna!
|
Prasanna P. |
Hi Mark!
|
Mark M. |
Prasanna: the others have had a shot already, so do you have a question
|
Mark M. |
?
|
Prasanna P. |
Yes
|
Prasanna P. |
View paste
|
Mark M. |
by "contact", you mean the contacts from the device's Contacts app, as seen in ContactsContract?
|
Prasanna P. |
yes
|
Mark M. |
in which case, I have absolutely no idea
|
Mark M. |
ContactsContract makes me break out in hives
|
Prasanna P. |
:)
|
Mar 21 | 7:55 PM |
Prasanna P. |
So is there another approach I could take?
|
Mark M. |
I did what I could with my chapter on it, but that's as far as I have ever taken it
|
Mark M. |
well, one of the identifier columns in ContactsContract is supposed to be durable
|
Mark M. |
you could have your own side table in your own app, keyed by that durable identifier, where you hold your additional data
|
Mark M. |
you'd have to do cleanup periodically to deal with added/removed contacts
|
Mark M. |
I am under the impression that apps are supposed
to be able to store other data in ContactsContract, but I do not know
the details
|
Prasanna P. |
so you mean to have the additional identifier in the durable column?
|
Mark M. |
I am not sure what "the additional identifier" means
|
Prasanna P. |
meant the boolean value I want to attached to a contact (in my team or not)
|
Mark M. |
basically, your database table would use the durable identifier as a foreign key of sorts to the ContactsContract provider
|
Prasanna P. |
ok
|
Mark M. |
booleans make for lousy identifiers, as you can only have two of them... :-)
|
Prasanna P. |
so when I do a cursor, how can do a join between the ContactsContract Data table and my table
|
Mark M. |
by hand
|
Mark M. |
or possibly a CursorJoiner
|
Prasanna P. |
so use sql syntax?
|
Mar 21 | 8:00 PM |
Mark M. |
well, for querying your own table, yes
|
Prasanna P. |
so can not use the Contacts content provider?
|
Mark M. |
there is the Contacts content provider (bad) and ContactsContract content provider (good)
|
Mark M. |
as I wrote earlier, I think there is a way you can store your data in ContactsContract directly, but I do not know the details
|
Gabriele | has left the room |
Prasanna P. |
ok.
|
Mark M. |
if you wish to instead maintain your own side
table, you'd query your table, query the ContactsContract provider, and
stitch together the results
|
Mark M. |
you cannot directly express a JOIN with a content
provider in general, let alone between a content provider and another
data source, like your own table
|
Prasanna P. |
So how do I know the tables names for the ContactsContract?
|
Prasanna P. |
and the columns?
|
Mark M. |
you do not know the table names
|
Mark M. |
you do not need the table names
|
Mark M. |
when you query a content provider, you use a Uri
|
Mark M. |
which roughly equates to a database + a table within that database
|
Prasanna P. |
ok
|
Mark M. |
column names are listed as constants on the ContactsContract set of classes
|
Mark M. |
you'll see some examples of querying ContactsContract in the chapter on contacts in the book
|
Prasanna P. |
ok
|
Mark M. |
let me take another question from Kevin, and I'll be back with you in a bit
|
Mark M. |
Kevin: do you have another question?
|
Prasanna P. |
Thanks Mark! Heading out.
|
Prasanna P. | has left the room |
Mar 21 | 8:05 PM |
Prasanna P. | has entered the room |
Mark M. |
hello again, Prasanna!
|
Mark M. |
Kevin: do you have another question?
|
Prasanna P. |
Hi Mark, what was the column you mentioned again? :)
|
Mark M. |
I am not sure what you are referring to
|
Prasanna P. |
the foreign key into the ContactsContract table?
|
Mark M. |
one of the various columns in the ContactsContract area is supposed to be a durable identifier
|
Prasanna P. |
oh yes. I read that in the documentation
|
Mark M. |
I think it may be LOOKUP_KEY
|
Mark M. |
but I am not completely certain
|
Mark M. |
did I mention that ContactsContract makes me break out in hives?
|
Prasanna P. |
That sounds correct. I will look it up
|
Prasanna P. |
:)
|
Prasanna P. |
I have another question, but will wait for Kevin
|
Mark M. |
Kevin: do you have another question?
|
Mar 21 | 8:10 PM |
Kevin M. | has left the room |
Mark M. |
Prasanna: go ahead
|
Prasanna P. |
So do you have another approach of solving what I want to do, given that ContactsContract is not very friendly?
|
Mark M. |
well, if you want to use device contacts, you have no real choice but to deal with ContactsContract on some level
|
Prasanna P. |
Basically I want to have a variable of my own
associated with each contact on the phone that I can use to display in a
list view with all the contacts
|
Mark M. |
understood
|
Mark M. |
which means that you need ContactsContract, to some degree
|
Mark M. |
either you are modifying ContactsContract's data to hold your data
|
Mark M. |
or you are holding your data separately and using some common identifier, foreign key-ish, to link them up
|
Prasanna P. |
so in the Data table I think there is a column
that indicated the data type and you can have your own data type. So I
can create my own data type to store my data in the Data table
|
Mark M. |
in theory, yes
|
Mar 21 | 8:15 PM |
Prasanna P. |
so for some contacts I will do this (let's say)
|
Prasanna P. |
But in the list view I want to show all the
contacts. So how would I use the content provider to get all the
contacts with 'my' variable for the contacts for which it is set
|
Mark M. |
you would include your column in your projection that you pass to your Loader, or query() on ContentResolver
|
Mark M. |
I presume that the engine for add-you-own-data has some notion of default values
|
Mark M. |
but, again, I have never messed with this area of ContactsContract
|
Prasanna P. |
ok
|
Mark M. |
as cortisone cream to combat the hives gets expensive
|
Prasanna P. |
:)
|
Prasanna P. |
Ok Mark. I will experiment on this. Should be a good exercise :)
|
Prasanna P. |
Have a Good night.
|
Mark M. |
you too!
|
Prasanna P. |
Talk to you later!
|
Prasanna P. | has left the room |
Mar 21 | 8:30 PM |
Mark M. | turned off guest access |