Office Hours — Today, October 23

Yesterday, October 22

Oct 23
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
bsr
has entered the room
Mark M.
howdy, bsr!
how can I help you today?
bsr
Hi mark.
We chat y'day night, and been struggling after a bit to make my list view selectable
I saw some explanation in the book
page 648
But, your code uses listeners.. etc. But I was originally following the API demo
I couldn't make selection state work with custom adapter
and custom view
is that the reason you use listeners, as you need to pass the state through parent activity
not sure
Mark M.
by "selection state", do you mean the highlight that appears when the user clicks on the row (briefly) or selects a row with the D-pad?
bsr
exactly
well, I have an android tablet
Mark M.
the selection state has nothing to do with listeners
the selection state is determined by the background of your rows
bsr
so, if I click with my finger, it briefly highlights the row, and details get updated
4:05 PM
Mark M.
when you say "custom view", what do you mean?
bsr
sorry, I was trying to look up the exact name
but, it is in Android namespace with _select_ .. 1
B3hrooz
has entered the room
bsr
It was used in API demo , list view layout example
Mark M.
bsr: I am sorry, but I do not know what you are referring to
B3hrooz
Hi Mark
bsr
please take qn from B3hrooz
Mark M.
(howdy, B3hrooz!)
bsr
I will look it up
Mark M.
bsr: OK
b3hrooz: do you have a question?
B3hrooz
yes absolutely
I couldn't find much related material in the book
so I thought I would ask you directly
Do you happen to know much about voice recognition API?
4:10 PM
Mark M.
sorry, I have not played with either text-to-speech or speech recognition much yet
it is on my list for 2013
B3hrooz
awesome
in that case, many thanks for your great book, it's been a great resource for me so far
Mark M.
you are very welcome, and thanks for the kind words!
B3hrooz
Have a great day :)
Mark M.
you too!
B3hrooz
has left the room
Mark M.
bsr: back to you!
bsr
Mark, I was originally using android.R.layout.simple_list_item_1
which handled the selection correctly
Mark M.
and that should have worked fine
bsr
then I followed the book to have custom adapter and view for each row
then, the selection works as the content updates
but, the color of row become normal after that
Mark M.
I am not sure what you mean by those last two entries
bsr
it is a list - master , 2 pane view
when I select on the left (list), the details updates
hence the selection works
but the list focus/color of the selected item
Mark M.
typically, for master-detail, you use the "activated" style, to keep a highlight on the row after the user taps
you will see "activated" introduced in the Large Screens chapter, in the EU4You sample app
4:15 PM
Mark M.
though full details are in the Advanced ListViews chapter
in the "Choice Modes and the Activated Style" section
bsr
I know, it is hard for you to help without code. I will make a test case if I couldn't figure this out, and post in SO
Mark M.
OK
bsr
thanks Mark, that's all.
have a good day
Mark M.
you too!
bsr
has left the room
4:20 PM
bsr
has entered the room
Mark M.
hello again!
bsr
:-)
View paste
class CountryAdapter extends ArrayAdapter<Country> { CountryAdapter() {
super(getActivity(), R.layout.row, R.id.name, Country.EU); }
I was wondering the significance of R.id.name
as I doubt whether that field decides the selection in the list view
Mark M.
that is the ID of the TextView inside the row layout that ArrayAdapter (the superclass of CountryAdapter) should manage itself
4:25 PM
bsr
so, if I load my data dynamically from a json array, each row will have a unique id
because I saw you define it in resource like
View paste
<string name="austria">Austria</string>
  <string name="belgium">Belgium</string>
  <string name="bulgaria">Bulgaria</string>
so, it creates one view for each item in countries list?
Mark M.
not really
ListView and ArrayAdapter recycle rows that scroll off the screen
bsr
I remember the ViewHolder patter :-)
Mark M.
only as many rows as is needed to fill the ListView (and perhaps 1-2 others) will be created
bsr
pattern :-)
ok
so, I can just use any unique id (int id from my json object) instead of defining it in resource file
Mark M.
sure
4:30 PM
Mark M.
you do not even really need a unique ID
for example, I do not use the string resource IDs for anything other than getting at the strings
in the sample you were pasting from earlier in this chat (EU4You)
bsr
I been studying that example.
can u please comment on why you used the interface to define the call back, or whether passing the selection through intent would work aswell
in the same example
Mark M.
I have no idea where you think an Intent would be involved in the handling of the ListView click event
I elected to use an interface to demonstrate using an interface
you might need that if there were two possible activities that held the fragment
in this case, there can only be one activity holding the CountriesFragment
so I could have cast getActivity() to be EU4You instead of CountryListener
bsr
I though the purpose was to pass the current selection
4:35 PM
bsr
which not sure could pass along with Bundle
thanks for explaining
Mark M.
you need to tell the hosting activity which Country was clicked upon
that's what the onListItemClick() method of the fragment does
then the activity can determine whether it can display the details itself or needs to start up some other activity to do that
bsr
thanks Mark . I will catch you next week :-)
thanks again for the help, and patience :-)
Mark M.
you are very welcome
bsr
has left the room
4:55 PM
Mark M.
turned off guest access

Yesterday, October 22

 

Office Hours

People in this transcript

  • B3hrooz
  • bsr
  • Mark Murphy