Problem with tabs and focus

by khose » Wed, 22 Apr 2009 02:15:54 GMT

Sponsored Links
 Hello all.

I've got another little issue using tabs.

I've created a new TabHost handling 4 Tabs. Each tab has an Intent as
content. The first tab launches a new Activity that creates a new
Options Menu. When i change the tab and then come back to the first
one, that menu wont show at first. I have to put the focus into one
View inside in order to make the menu show again.

I've tried requesting focus inside the first Activity..

        protected void onResume() {

i've also tried this...

public class MainActivity extends TabActivity {
    public void onCreate(Bundle savedInstanceState) {
        _tabhost = getTabHost();


But no luck at all... :S

Any Idea???


Problem with tabs and focus

by khose » Wed, 22 Apr 2009 19:31:12 GMT

 Any idea?? I've seen that everythig goes right when you define your
layout inside the tab container XML and you manage all the tabs within
the TabActivity. But its really confusing when you throw intents
instead. I also have some issues with the menu that each tab is
showing up....


Sponsored Links

Problem with tabs and focus

by Mark Murphy » Wed, 22 Apr 2009 19:42:49 GMT


Frankly, I have yet to see a good reason to use Intents to populate
tabs, particularly since you are limited to your own activities.

If this were my code, I would:

1. Move the UI logic for each of the activities to be put into tabs into
custom View classes rather than activity classes.

2. For those where I need the UI logic to appear both in a tab and in a
standalone activity, create a trivial activity wrapper around the view.

3. Use the custom View classes from step #1 in the TabActivity instead
of Intents.

4. Put the option menus in the TabActivity.

But, hey, that's just me.

Mark Murphy (a Commons Guy)  | 

Android App Developer Training: 


Problem with tabs and focus

by khose » Wed, 22 Apr 2009 22:35:13 GMT

 Ok, understood. But i can't change now the way i manage those tabs. I
will consider your solution in future apps.
I think that the main reason to use Intents instead of views is that
some views can be hard to manage and the final TabActivity can be
really heavy to load and really ugly to read (the code i mean). So now
i need a "real" solution...

Thanks anyway Mark.


Problem with tabs and focus

by khose » Wed, 29 Apr 2009 02:32:58 GMT

 So, ive seen that the view inside that tab has focus. So it cant be a
focus problem. Its a strange behaviour bcos an edittext get the focus,
but its not orange-highlighted. I press down and up in the pad and
that edittext gets highlighted. If i press menu button after that,
then i can see the menu. (Its the only way to "force" it to appear...)



Other Threads


I have a couple different questions:

1) Does Google think there will only be one screen size on Android
phones?  The reason I ask is because I haven't been able to find
anything on "variable" layouts in Android?  I would like to create a
layout with 2 webviews, one 80% of screen height and the other 20%.
Is this even possible, or do I need to assign the height of each as a
static "px" value?

2) How do I preserve the data in my views when someone switches
between landscape and portrait?  I doubt it's hard, but I've not been
able to find it.  Can someone post an example?

Thanks everyone!

2. Log level change in Java files

Hi all,
How can I change log level of a particular middleware module in Java
(e.g. Telephony manager)? Can I change log level during run time?


3. applications requiring excessive permissions

4. bootloader operation during update-radio

5. Encryption, Remote Admin, Framework, 2.0...

6. Reg playing youtube video in android

7. object serialization ???