Android UI – making the simple things virtually impossible

Know what I need? A “Stupid Android UI Tricks” book. I swear, there’s just so much about programming the native UI that just seems completely random and ass-backward. Are all UI APIs this bad?

Here’s the latest fun: I created a dialog where you can enter something in a text editor field. Only, you can’t on my Nexus, because the soft keyboard won’t come up. I don’t know if that’s normal behavior or if I attached something to the field that gets in the way of the keyboard showing up. I thought maybe it was the OnFocusChangeListener I’d set, but I commented that bit out and it still won’t come up. As an aside, sort of, it’s stupid that you can only add one listener for any given event. I have a dialog where I attach a listener in the generic superclass, and then I want to add to that event’s behavior in a subclass. Can’t  do it. I’d have to duplicate or proxy all of the behavior from the parent listener. Where’s the reuse of code? Why aren’t listeners all implemented as daisy chains?

While I’m ranting, why do I even bother creating dialogs? Every time I do, I find something about its intended behavior that requires an Activity to be in play. The latest: I have a dialog where I want to let the user pick a ringtone. Problem is, the only API exposed for this involves a call to startActivityForResult, and how is that result returned? By the onActivityResult callback on the calling Activity. So if you have a dialog and want the user to pick a ringtone, you have to get the Activity to relay the result to the dialog, which means recording the current dialog in a field somewhere in the activity, and adding a callback method on the activity that could have been totally avoided just by adding an implementation of startActivityForResult that accepted a listener for the result. Would that be so hard? Anyway I think the lesson is to create all non-trivial dialogs as Activities that are just styled as dialogs.

Back to the problem at hand. What else might be going on with my missing keyboard? Here’s someone with a similar problem, (and a long thread on the same topic), though I think they’re just not getting the keyboard at dialog start, not failing to get it ever. Anyway I shouldn’t have to add a listener just to get a keyboard. That’s ridiculous. Android should handle this automatically. What could I be doing that’s interfering?

BTW, its layout looks like this:

 android:layout_width="wrap_content" />

I created a completely unattached text editor (no listeners or anything) in my dialog and also couldn’t get a keyboard to come up for that.

Another random ranty aside: seriously, WordPress, why is the post input text area so small by default? The post is the center of attention; it should be as big as possible without crowding out the editing icons. Yeah, I know I can drag around the corner to resize, but I don’t wanna, ok?


2 Responses

  1. Figured out the problem with my dialog. Not surprisingly, my own stupid fault. Somewhere back in the mists of time, I added this little bit of code to my dialog:

    // make sure only the dialog has focus

    That’s straight out of this SDK link:

    Evidently I totally misunderstood its purpose.

  2. Ha, that comment you wrote a while ago should have read

    /* screw myself over later when I want focus somewhere else */

    Nice blog, think I’ll keep reading.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: