Office Hours — Today, September 4

Thursday, August 30

Sep 4
3:55 PM
Mark M.
has entered the room
Mark M.
turned on guest access
4:00 PM
Prasanna
has entered the room
Mark M.
howdy, Prasanna!
Prasanna
Hi Mark
Mark M.
how can I help you today?
Prasanna
I am using a simplecursor adapter with a list view. I am using a custom row that has 3 textfields and a button to populate the list. The 3 text fields are populated from the database. When you click on the button I want to show and alert with detail information which I want obtain from the relevant row in the database. How do I set a onClickListener to the button in a way that I am able to get access to the relevant row in the cursor?
Mark M.
personally, I *really* don
er
personally, I *really* don't like ListView holding rows that are this interactive
if there are only a few rows (say, less than 50), use a vertical LinearLayout in a ScrollView
Prasanna
there will be more than 50 rows
Mark M.
in which case, this should not be in one ListView, IMHO
be that as it may
4:05 PM
Mark M.
that sample project shows how to attach listeners to widgets in a ListView row (in this case, a RatingBar) with knowledge of what position they are associated with
Prasanna
ok
so, if I am not to use a ListView for this, how would I proceed?
Mark M.
having a ListView is fine, but the data entry should not be in-line in the ListView, but in a detail fragment/activity/whateer
er, whatever
(BTW, the sample app I mentioned is described on pages 733-737 of Version 4.1 of the book)
Prasanna
ok thanks Mark.
There is not going to be data entry for this implementation in the ListView.
Mark M.
you said that there are "3 text fields" in the rows
Prasanna
oh, meant textview
sorry
Mark M.
if you really mean three TextViews, then I don't know why you need the button -- just respond to taps on the rows themselves, the way ListViews normally work
4:10 PM
Prasanna
Good point. I think I will respond to the taps on the row. The button was what the client had in mind ...
Do you have an example in your book on respond to the row tap
Mark M.
if you are using ListActivity or ListFragment, just override onListItemClick()
lots of samples show that
Prasanna
ok
Mark M.
if not, you will need to call setOnItemClickListener() on the ListView, supplying an OnItemClickListener implementation
Prasanna
got it
Another question ...
I have a list view that has 3 columns that are populated using a cursor adapter. I want to provide a search box for the user to serch the text in any of the 3 columns. Any hints on how I would go about doign this
Mark M.
which part of "this" are you concerned about?
Prasanna
is there any component, api etc that I can use for search the data in a sqlite database
4:15 PM
Mark M.
um, well you search a SQLite database by executing a query, via rawQuery() or kin
that's how you got your Cursor for your CursorAdapter in the first place, presumably
Prasanna
yes
Mark M.
so, if you want to search the contents of the database, create and execute another query
Prasanna
ok
so just bring up an alert to collect the text to search and execute a query and show the results I guess ...
Mark M.
you can bring up the standard search field if you prefer, vs. a dialog
Prasanna
how do I do this?
Mark M.
see Searching with SearchManager, starting on page 1247, of Version 4.1 of the book :-)
Prasanna
thanks Mark
4:20 PM
Prasanna
I will refer to the book, thanks directing me.
Ok Mark. Heading out. Hope you have a great rest of the day.
Mark M.
you too!
Prasanna
has left the room
Prasanna
has entered the room
Prasanna
Actually I more question
Mark M.
hi again! :-)
Prasanna
On the same ListView, I want to implement sorting on a few columns ...
I am thinking of having buttons on top of the relevant columns, so that when you press on one of these buttons ...
I will execute the query again doing the relevant sort and populating the ListView again ...
Am I doing the right thing here?
Mark M.
in terms of re-querying the database, that is certainly simplest
if speed is an issue, you could look to do more stuff in-memory to do the sort on the original query result
4:25 PM
Mark M.
in terms of the buttons-on-top-of-the-columns, I don't see that UI approach taken often
sort is either triggered by an options menu/action bar item, or perhaps a Spinner in the UI itself
basically, so a single errant tap doesn't lose the user's place, presumably
Prasanna
yes, makes sense
do you have an example in your book similar to re-querying the database and showing results again?
Mark M.
well, the search sample in the chapter I mentioned shows displaying search results
it's not in a database, though
I do not have a sample that shows implementing search with database-backed content, sorry
Prasanna
do you have a an example that does just queries the database again and shows the results in a ListView
Mark M.
not in terms of "again"
I have samples that show querying a database, but only on startup, not based on user input
4:30 PM
Mark M.
in the case of sorting, you'd just use swapCursor() or changeCursor() on your CursorAdapter to load in new results
actually, my database samples do show re-loading the database contents after rows are added
Prasanna
great
crazykid
has entered the room
Mark M.
howdy, crazykid!
Prasanna
thanks Mark.
crazykid
hi Mark
Prasanna
has left the room
Mark M.
Prasanna: sure
crazykid: how can I help you today?
crazykid
i've decided that my main navigation is better suited for tabhost - I may utilize the view pager inside one of the tab's for sub-navigation, but the view pager doesn't really fit the overall feel we are going for
KBZoiD
has entered the room
Mark M.
crazykid: sorry, I need a bit more context as to what you are talking about
(BTW, howdy, um, KBZoiD!)
KBZoiD
hello everyone
hi Mark :)
4:35 PM
crazykid
right now i am following the tutorial on tabhost and tabwidget...its set up in a way to load views. is it wrong to have the tabs load activities instead?
hi KB
Mark M.
activities-in-tabs is officially deprecated
crazykid
sorry mark I was referring to our convo last week regarding the different methods for navigation in my current project
mind if i upload an image?
Mark M.
I apologize for not necessarily remembering everything from week to week in the chats
heck, some days I barely remember what I had for breakfast :-)
yes, feel free to upload an image
crazykid
i know my fault
Mark M.
FWIW, bottom tabs are frowned upon: http://developer.android.com/design/patter…
crazykid
so in this app, the navigation at the bottom loads a new activity in the main area..I assume its a activity because the back button returns you to the previous view
Mark M.
the BACK button behavior has no bearing here
crazykid
hrmm, ok how about this ::uploading another file::
Mark M.
activities-in-tabs would exit the whole tab set on a BACK press too
crazykid
Mark M.
they have overridden onBackPressed() to have alternative behavior
crazykid
oh ok
Mark M.
overriding onBackPressed() does not have much to do with how the contents are rendered
so that could have been views-in-tabs, activities-in-tabs, or something else entirely
4:40 PM
crazykid
ok
Mark M.
if the classic TabHost gives you your desired look, that's fine, though I'd still look into how you can re-implement the TabWidget style in the form of an indicator to go with ViewPager
swiping between "tabs" is getting fairly popular
to the point where users may start expecting it
crazykid
roger
so i can set up the "global" tabbed navigation in the viewpager?
i mean the look and feel
Mark M.
I hesitate a bit on the word "in"
the content is "in" the ViewPager
the tabs are an indicator associated with the ViewPager
depending on implementation, that indicator strip may be a child or sibling of the ViewPager
let me take a question from KBZoiD, then circle back to you for more follow-up
KBZoiD: do you have a question?
crazykid
sounds good
4:45 PM
KBZoiD
no no, no problem :D im just starting reading your book and reading other people's questions is quite useful for me :)
thank you anyway! i understand it all so far :P
Mark M.
oh, OK
crazykid: back to you, then
crazykid
yea so I guess I just need to get my head around viewpager a little better
Mark M.
there's a whole chapter on it in the book :-)
the tutorials also use it, FWIW
KBZoiD
gotta go now. nice to meet you guys and thank you for the book Mark
catch you guys soon
bye
crazykid
haha, i know and i had no issues while reading / doing the examples..now when applying it to my app and navigation issue I'm having a tough time figuring out how to incorporate
bye KB
4:50 PM
crazykid
but I'll just re-read :)
one more thing
so any resource I see (stackoverflow, etc) loading activities via tabs I should avoid, correct?
Mark M.
again, that technique is deprecated
it probably still works as well as it ever did, but I would go in other directions
crazykid
ok, how about fragments in tabs?
Mark M.
that's perfectly reasonable and is the preferred alternative to activities-in-tabs
crazykid
ok cool, thanks mark
4:55 PM
crazykid
adios
Mark M.
have a pleasant day, both of you!
crazykid
has left the room
5:00 PM
KBZoiD
has left the room
Mark M.
that is a wrap for today's chat
the next one is Thursday, 10am Eastern
Mark M.
turned off guest access

Thursday, August 30

 

Office Hours

People in this transcript

  • crazykid
  • KBZoiD
  • Mark Murphy
  • Prasanna