开发者

Problem changing Activity title onActivityResult

I have a simple app based on the Notepad demo application, and when a user is viewing/editing a note they can launch the dialog activity (TitleEditor) that allows them to change the title of a note. Currently, when viewing/editing a note, the notes' current title is shown as the activity title.

So, I launch the TitleEditor dialog activity with startActivityForResult(), and in onActivityResult() I am successfully getting the new ti开发者_JAVA百科tle back, no problem.

The issue relates to then updating the notes view/edit (the active activity) title... using setTitle() in onActivityResult() with the data passed back does seem to set the title internally (a subsequent call to getTitle() shows the new title has been set), but the actual UI title is not updated until the activity is closed and then re-launched.

I've used setTitle() in onResume(), and it worked like a charm, but not working here... maybe due to the Activity being 'active'? Is there any way to change the title of an active activity?

Thanks,

Paul


I'm not sure what would be different in onActivityResult() but I've just tried this in a test-bed activity I play around with.

Using setTitle("My New Title");in the onClick() handler for a button in my activity changes the title immediately.

The only thing I could think of is if you have overridden onTitleChanged(...) and you're not calling super.onTitleChanged(...) from within it.


Found the issue... I was changing the title of the note in the data set the called activity, then setting the new title in onActivityResult(), BUT had forgotten to also update the cursor on the activity..., so in onResume() (called after the title edit activity ended), I was then setTitle()ing the title from the cursor, which hadn't been updated to reflect the new data.

Calling mCursor.requery() on a successful renaming result in onActivityResult() fixed it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜