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

1. how to run C/C++ applications on Android

I have some nice UI nuggets written in C, how shall I port them on
thanks a bunch.


2. Box2d Graphics In Android

Hi all

Anybody know about this Box2d in android Can u give more details about
this rather thatan that circle example given in ......

and one more thing is there any frameworks or developing the 2D games

for example a man is moving on the road and shoot the enimies by gun
like this i want to develop an epplication

please help me regarding this

Thanks in advance


3. opengl MultiThread textureMap

4. How is WebView implemented under the hood

5. IME options behavior is inconsistent across different devices

6. Networking without wireless

7. Connect laptop built-in gps receiver to emulator