Office Hours — Today, July 9

Saturday, July 6

Jul 9
7:15 PM
Mark M.
has entered the room
Mark M.
turned on guest access
7:20 PM
Mark M.
has entered the room
Mark M.
testing
Mark M.
testing
Mark M.
has left the room
jdub
has entered the room
Mark M.
hello, jdub
how can I help you today?
jdub
Hi Mark
I am having difficulty putting a HorizontalListView (DevSmartLIb code) into a ListView
Mark M.
I have never used HorizontalListView
jdub
Ok.
Mark M.
jdub
Yes
Mark M.
what specific problem are you encountering?
jdub
Well
Mark M.
not sure that I can help, but maybe I'll get lucky... :-)
jdub
Ok :-) Here goes
HorizontalListview is its own class and in its own layout
7:25 PM
jdub
If I setContentView on that layout and provide the adapter, the horizontal scrolling works
But If I try to add that layout to another ListView, nothing happens. Its as though setContentView only alllows one List to be populated
Sorry if I am explaining it in a confusingg way
Mark M.
when you say "add that layout to another ListView", you mean using that layout as rows from the ListView's own adapter?
jdub
I don't quite understand everthing I am doing
EGHDK
has entered the room
Mark M.
(hello, EGHDK -- be with you shortly!)
jdub
Well In other words, each HorizontalView object becomes a entry into the "Vertical" ListView
Mark M.
and how are you doing that?
jdub
Not ver successfully I am afraid
Mark M.
OK, I'll ask again: when you say "add that layout to another ListView", you mean using that layout as rows from the ListView's own adapter?
7:30 PM
Mark M.
in other words, what are you using for the adapter for the ListView?
jdub
A new adapter
Can I show you the code?
It is small
Mark M.
sure, if you can link to it, or paste it here
and you don't mind the world seeing it :-)
jdub
As long as the world won't hold me liable :-)
Hang on.. let me get it. If you want to answer the other person, that will give time
Mark M.
OK
EGHDK: do you have a question?
EGHDK
View paste
Yeah, I've been working on this for about 8 hours over the past few days and I can't get anything that'll work.
http://stackoverflow.com/questions/17415167/programatically-add-multiple-buttons-to-layout
Mark M.
aw, c'mon, I kinda like the look of the sixth "hello" :-)
EGHDK
Hahaha. Problem is, that there are four more hello's right after it that don't show!
Mark M.
FlowLayout was the old Swing component that did this sort of "word wrapping"
EGHDK
View paste
I tried a gridLayout, but to no avail.
http://stackoverflow.com/questions/17535652/gridlayout-wont-display-in-a-grid
7:35 PM
Mark M.
they both provide links or inline code for various FlowLayout-style containers
EGHDK
Hmm, heard of "Swing" before, but never used it so I'm not familiar with it.
Mark M.
GridLayout can also do this, if you use columnCount
Swing is a Java desktop UI framework
EGHDK
But, awesome, I should be able to use those links to complete my task. Using a GridLayout is probably not what I want to do I guess... right?
Mark M.
probably two-thirds of Java desktop apps use Swing for their UI
EGHDK
Gotcha. That makes sense now.
Mark M.
I have not played with GridLayout in the form of having it be a FlowLayout-style replacement, though it should be possible
it has the advantage of being Google-supported (and built into API Level 11+, in addition to the Android Support package)
at the end of the day, though, go with whatever works and you are comfortable with
EGHDK
Wait, so flowLayout only works which API?
Mark M.
I have no idea
there is no FlowLayout in Android, only third-party implementations
as referenced in those two StackOverflow links
EGHDK
Hmmm... alright so I'll have to look into it. Gotcha.
Mark M.
let's switch back to jdub
jdub: are you ready to continue?
jdub
Ok
EGHDK
Well, if you want to take a look at this question and answer it in your spare time you can go ahead ;)
jdub
So this won't work but it captures I am trying to do
View paste (7 more lines)
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.listviewdemo);	
		
		
		listview = (HorizontalListView)findViewById(R.id.listview);
				

		listview.setAdapter(mAdapter);	
		
		
		// --- Get the ListView in this Activity
		lv = (ListView)findViewById(R.id.listView1);
		
		hlv = new ArrayList<Integer>();
...
7:40 PM
jdub
Naturally I left out a lot
Mark M.
sorry, but I'm lost
jdub
Oh no!!!! :-)
Allow me to explain
Mark M.
I fail to see where listview is used anywhere
other than as a widget in your existing layout
if you want HorizontalListViews to be the rows of your ListView, your adapter for the ListView needs to return HorizontalListViews from getView(), by one means or another
jdub
It does
Mark M.
I'll take your word for that
jdub
You are correct I didn't copy in the overidden getView method
Mark M.
then I am confused by your layouts
jdub
The problem seems to be that the getView method doesn't get called for the layout that is not specified in setContentView
Go ahead
Mark M.
your layout for the activity is R.layout.listviewdemo
*and* your layout for your rows is *also* R.layout.listviewdemo?
jdub
Yes
Mark M.
how does that work?
jdub
It doesn't
You are corect.
The problem I am having is
setContentView seems to infalte the layout I specify
If I specify the listviewdemo
I get the horizontal scroll
7:45 PM
jdub
If I specify the other layout with the list view (and put in say some buttons)
I get the vertical ListView
I can't do both
Mark M.
that's because you should have more than one layout file
jdub
Ok
Mark M.
one for the activity, containing your ListView
a second one that serves as the template for your rows, containing your HorizontalListView
jdub
Ok let me take a look at these...
Mark M.
in those cases, I do not bother with setContentView(), as I am using ListActivity, which supplies a ListView automatically
my layout in each case -- row.xml -- is used to populate the rows
the first one's row is an ImageView and a pair of TextViews
the second one's row is a RatingBar and a TextView
Yurii L.
has entered the room
jdub
Now ListViewActivity makes the whole activity a listview correct?
Mark M.
by default, yes
you *can* call setContentView() on a ListActivity, so long as you have a ListView in the layout that is named android:id="@android:id/list"
but you don't have to if a full-screen ListView is all you need
Yurii L.
Hello everyone.
Mark M.
(hello, Yurii -- I'll be with you in just a moment)
jdub
Ok Mark. Thanks let me chase this dowm
Mark M.
OK
jdub
ThankYOU!!!!!!!
Mark M.
Yurii: you have not had a chance to ask a question yet, so -- do you have a question?
jdub
Ive been fighting this fopr day
Yurii L.
sure, Mark, what is the best way to have reusable FragmentDialogs
7:50 PM
Mark M.
what do you mean by "reusable" in this context?
7:50 PM
Yurii L.
in code I working on, me colleague used dialog builder by passing runnable to be executed on yes or no clicks
Mark M.
I suppose you could somehow do the same thing for a DialogFragment
Yurii L.
instead of creating class for each dialog, I'd like to have fragment dialog to which I can set content, and some action,
Mark M.
personally, I'd use the contract pattern, to have the DialogFragment call methods on the hosting activity when events occur
Yurii L.
how can I pass runnable to dialogfragment?
Mark M.
call a method on your DialogFragment
one that takes a Runnable and does cool stuff with it
Yurii L.
with one activity architechture, should I do the same in coresponding fragments?
Mark M.
I am sorry, but I do not understand what you mean by that
Yurii L.
I have one activity which can hold many fragments, then from fragmen A I want to show DialogFragment D,
if I use contract pattern, I should created callbacks in Fragment A?
Mark M.
personally, I'd argue that Fragment A wants something to happen, and it is the activity's job to determine how to satisfy that
I do not like fragments working directly with other fragments, as it breaks the fragment UI encapsulation
7:55 PM
Mark M.
I have not experimented with the contract pattern for a fragment interacting with another fragment, so I do not know exactly how I would approach that -- sorry
Yurii L.
but in one activity architecture how will you differ one dialog fragment from another?
Mark M.
by class, or by tag
depending on where you are trying to determine the difference
e.g., when trying to retrieve the fragment from a FragmentManager, you usually use a tag with a DialogFragment
Yurii L.
thanks.
Mark M.
let me take questions from the others, and I will come back to you in a bit
EGHDK: do you have another question?
EGHDK
Eh, sort of. Don't know if this is really explainable but I'll give it a shot.
I want to create a game without using OpenGL or unity or anything. Purely a "Java" 2d game.
Before I start I'm realizing that different screen sizes and aspect ratios can really mess up my game. Any ways around that?
8:00 PM
Mark M.
um
Liam
has entered the room
Mark M.
I am sure that there is more specific game advice you can get on this subject from whatever game engine you're using (e.g., andEngine)
beyond that, it would all depend on the game in question
board game vs. side-shooter vs. ...
and since I'm not a game developer, I can only kinda sorta hand-wave around answers
(BTW, hello, Liam -- I will be with you shortly!)
EGHDK
I simply want a square on the bottom of the screen.
Liam
Hey Mark. Thanks.
Mark M.
then have a square on the bottom of the screen
EGHDK
And a sqaure flies from the top of the screen and I have to move my controls to make the two connect.
Mark M.
there is no screen size or aspect ratio that would prevent you from having a square on the bottom of the screen
that too should be fairly flexible for handling screen sizes and aspect ratios
EGHDK
I'll restructure my question, and come back next week with a more detailed scenario. Thanks
Mark M.
OK
Liam: do you have a question?
Liam
yep.. So my question may be a little bit complicated, but I am going to give it a shot as it has had me stuck for a couple of weeks now.
In my app, I am catching a phone call with a broadcast receiver and then launching a new activity from the broadcast receiver. My app works perfectly 99% of the time, but when the user misses the call the phoneApp acquires a wakelock and prevents the phone from going to sleep. I used the adb dumpsys power to make sure that is the only wakelock being acquired.
Any ideas about how to either shut down the phoneApp, clear the wakelock, or some other way to solve the issue?
Mark M.
is "the phoneApp" your app?
or are you really referring to the OS's dialer/phone app?
Liam
no sorry that is the native phone application i beleive
8:05 PM
Liam
actual message in adb is
PhoneApp'ACQUIRE_CAUSES_WAKEUP activated
Mark M.
yeah, I have no idea
to be honest, I really dislike the family of "intercept the call and interpose something" apps
simply because the framework is not set up for it, and you'll run into problems like this
Liam
okay, no worries. I will keep searching. No way to do a generic clear wakelock right?
Mark M.
no, and definitely not one that's not your own
Liam
okay, that is what i thought. Thanks anyway
Mark M.
sorry I could not be of greater assistance
jdub: do you have another question?
jdub
No I am trying your suggestion now
Mark M.
OK
jdub
I think they will work for me
Mark M.
Yurii: do you have another question?
Yurii L.
sure, what is your suggestion on having viewpager inside slidingpane layotu
Mark M.
I have not tried that, and I can definitely see where there could be problems
Yurii L.
is it posible to make a handle in SlidingPane?
like 20dp on the left to slide in and out
Mark M.
visually, you can do what you want, just by putting something on that side
8:10 PM
Mark M.
functionally, I don't see an API to control the width of the touch zone
if your content for the "pane" could at all be considered "navigation", I'd consider using DrawerLayout
at least there, you can add the affordance to the action bar
Yurii L.
drawer is already heavily used, application have too deep navigation...
Mark M.
oh, I'd be very concerned with having *both* SlidingPaneLayout *and* DrawerLayout (or a third-party equivalent)
the combination of all those left-edge touch events is likely to tie your app in knots
particularly with your main view being a ViewPager
Yurii L.
do you think it is reasonable to have simple tabs? it would solve some problem, but I feel like Android users used to swipe between them
Mark M.
but, beyond that, I do not know of a SlidingPaneLayout + ViewPager recipe, sorry
switching the ViewPager to be a FragmentTabHost or something would simplify the gestures
I agree that it would be nice to offer swiping as well
Yurii L.
thanks
Mark M.
but I have no idea how best to combine all of those
sorry
EGHDK: do you have another question?
8:15 PM
EGHDK
I have a button that creates a DialogFragment, but if I click the button really fast the DialogFragment opens twice. Any quick way to make sure nothing else opens up once the DialogFragment is hit?
Button is hit*
Mark M.
you can disable the button (setEnabled(false)), which will help some
EGHDK
So when my dialog is dismissed I have to setEnabled(true)?
Mark M.
presumably
whenever you want the user to be able to press the button again
EGHDK
Same thing for all of the other buttons on the screen then... I guess right?
Mark M.
I'd worry more about minimizing the time it takes to get the dialog shown
but, yes, if you are concerned about button clicks in the interval between the launch-the-dialog click and the dialog taking over touch events, you would need to disable them
and enable them later
EGHDK
It shows up pretty much "instantly", but again if I try hard enough I can click it twice.
Mark M.
you need to decide for yourself how much you want to engineer for this case
EGHDK
Okay, yeah I was guessing that would be the answer.
Mark M.
it's theoretically possible for you to put up a "glass pane" -- some transparent View that overlays all the buttons but would be behind the dialog
I have not tried that on Android, though it's an old Swing trick
it also would not give the user any visual feedback that the buttons would not work
EGHDK
Swing to the rescue!
Mark M.
Liam: do you have another question?
8:20 PM
Mark M.
OK, if anyone has a question, chime in
jdub
Will these notes be archived immediately Mark? In case I want to go back to your suggestions?
Mark M.
they will appear at http://commonsware.com/office-hours/ shortly after the chat ends
jdub
Ok Thanks
EGHDK
I have "<requestFocus>" in two of my xml layouts. The one deeper inside my app works with no problem, but the one on the MainActivity launcher activity has a cursor blinking in the editText, but doesn't pull up the keyboard. Any ideas?
Mark M.
did you test this on hardware, or on the emulator?
EGHDK
Both, and both don't work.
Mark M.
I seem to recall that focus on EditText widgets is weird, but I do not remember specifics about this situation
EGHDK
It's funny because the simpler "xml layout" won't work. All it has is an ImageView and an editText, and my other layout has a ton of stuff going on.
Mark M.
is the EditText visually getting the focus (e.g., right highlights), beyond just the cursor?
8:25 PM
EGHDK
Also, if I remove requestFocus, the blinking cursor dissapears.
8:25 PM
EGHDK
Hmm... not sure because I have the background simply set to a @color
Mark M.
on an EditText? ick
EGHDK
same exact way it's being done on the layout thats "working".
Mark M.
you might poke through https://github.com/commonsguy/cw-omnibus/tree/m... and the Focus Management chapter and see if anything leaps out at you
EGHDK
Alright, will do. I guess I'll just play around with it some more.
Mark M.
I was fighting with the reverse today, trying to get the input method editor to go away after executing a search with a SearchView
(BTW, full-text search coming in the APK formats of future editions of the book!)
EGHDK
Yeah, just can't seem to win em'. Thanks though
Sounds awesome! hahah
I've got two more questions, but I'll save them for next time. Thanks again, see you on thursday.
Mark M.
yes, the next chat will be Thursday at 7:30pm Eastern
Yurii L.
Last quick question? Do you use dependency injection? Any chance to add How to use Dagger in the book?
Mark M.
I have never used DI, and so I'm unlikely to add a Dagger chapter any time soon
Yurii L.
thanks
8:30 PM
Mark M.
well, that's a wrap for today's chat
jdub
Thx Mark
Mark M.
have a pleasant day, all!
Yurii L.
thanks you too!
Liam
has left the room
jdub
has left the room
EGHDK
has left the room
Yurii L.
has left the room
Mark M.
turned off guest access

Saturday, July 6

 

Office Hours

People in this transcript

  • EGHDK
  • jdub
  • Liam
  • Mark Murphy
  • Mark Murphy's Test Clone
  • Yurii Laguta