Thursday, June 5, 2014


Haven't had much to write about the past couple of days.  Things seem to be going really smoothly; longest I've gotten stuck was for an hour or two, fixing a bug that showed up when I modified my database to cascade on delete.  Turned out the SQLiteDatabase.replace function does strange things when the database is set up to cascade, so I ended up re-writing a few functions to avoid using that.  Other than that little hiccup, I've been making a lot of progress.  In fact, this app should be ready to release by the end of next week at the latest.

I did run into an interesting issue today though.  I wanted to make the soft keyboard pop up whenever I show a dialog, so users don't have to tap the text field an extra time. I had to try a couple different things to get it to work correctly. 

The first method that appeared to work was to use:



And a similar method to hide the keyboard.  But I had some issues depending on where I put the function.  Sometimes, it wouldn't show itself, other times it wouldn't hide, even if you quit the app.

I ended up using something like this:
But this had an interesting problem of its own.  It worked flawlessly for one dialog (it even knew when to close itself, unlike the other method where you had to force it to close), but when I put the exact same code in another dialog, it didn't work.  Both of them started with the correct editText in focus, but the problem was caused by when the field was put into focus.  The second dialog used a custom layout, and in the XML I had added the <requestFocus /> tag, because I obviously wanted to start with that field focused.  (Turns out I didn't need to, because I guess the first editText is automatically focused, but that's besides the point.)  The problem was, because I asked for focus in the XML, the field started with focus before I established the listener.  Therefore, there was no change of focus to trigger the listener.  All I had to do was remove that tag, and it worked flawlessly.  (Ignoring the fact that it will show the soft keyboard even when a physical keyboard is present.)

So yeah, that was kind of interesting.  (Finally I can share something helpful that I learned!)

No comments:

Post a Comment