TabHost crash in setup

by Patrick » Tue, 13 Jan 2009 03:04:09 GMT


Sponsored Links
 I can't seem to get a TabHost to work. I am not extending TabActivity.
The tabs are part of the UI, but I don't want them to be the full
screen, but instead be part of the main layout. Think of it as in most
tabbed dialog in windows, where the OK and Cancel buttons are not
inside the tabs.

I've tried just having the TabHost inside a LinearLayout in the xml. I
get the TabHost view with findById, call setup, and crash.

I tried adding a FrameLayout manually as a child of the TabHost in the
xml, but the same thing happens.

There were other posts about this, and the answer seems to have been
"Use TabActivity". But in my case, I can't (Or at least would rather
not). I don't need to have it launch an activity per tab. I just need
it to, well, behave like tab controls do in other systems : tell me
which one is selected, and show the user only the subview associated
with the selected tab.

Is there a bug in TabHost that makes it unusable without TabActivity ?

--~--~---------~--~----~------------~-------~--~----~



TabHost crash in setup

by Mark Murphy » Tue, 13 Jan 2009 03:25:51 GMT


 


I think that is a problem.


Yup.


Then don't use the built-in tabs mechanism. Use a ViewFlipper and roll
your own tabs.


Is there a bug in your car that makes in unusable without fuel?

In other words, the fact that TabHost may depend upon TabActivity is not
a bug, but rather a dependency, one that might need better documentation.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
Android Training in Sweden --  http://www.sotrium.com/training.php 

--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


TabHost crash in setup

by skink » Tue, 13 Jan 2009 03:55:04 GMT


 




why? if you call TabHost's setup() it works like a charm.

pskink
--~--~---------~--~----~------------~-------~--~----~



TabHost crash in setup

by Mark Murphy » Tue, 13 Jan 2009 04:04:59 GMT


 


My apologies.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 

Android Training on the Ranch! -- Mar 16-20, 2009
 http://www.bignerdranch.com/schedule.shtml 

--~--~---------~--~----~------------~-------~--~----~



TabHost crash in setup

by Patrick » Tue, 13 Jan 2009 08:20:05 GMT


 To say that TabHost not working without deriving from TabActivity is
not a bug is a bit strange. Buttons do not require the activity to
derive from ButtonActivity to not crash, do they? And it's not lilke a
car not working without fuel. It's more like a car not working because
there are other cars on the road. A tab control is not some new UI
design unique to Android that only makes sense in a very specific
context, so it's not unreasonable to expect it to work like every
other UI elements : I should be able to place one in my layout
wherever I want, or maybe even have two of them in the same layout,
and it should not crash. I should be able to get the selected tab of
each of them individually, and do whatever processing I wish based on
that information.

That aside, what skinks mention is precisely where my problem lies :
the call to setup() crashes.

I've seen another post where someone posted their XML layout, and they
had manually added a TabWidget and FrameLayout with specific android
IDs as children of the TabHost. I thought from reading the docs that
creating those was what setup was for. It seems like a really bad idea
to manually build UI elements that are OS dependent, since some future
version might have different internal requirements and the app would
no longer work.

So the question remains. Which of the following applies :
1. It is a bug (ie. Some future OS version will fix it).
2. TabHost will never work outside of TabActivity. (It should then be
removed from the classes creatable in the layout editor)
3. It works, but there is something I'm supposed to call on it/add in
the XML that I missed or isn't in the docs. (For example, it cannot be
a child of a LinearLayout)
4. Nobody knows. It works perfectly fine for other people, and I'm
just unlucky.

--~--~---------~--~----~------------~-------~--~----~



TabHost crash in setup

by Mark Murphy » Tue, 13 Jan 2009 11:28:52 GMT


 


You have a preconceived notion of how tabs should work, and Android's
tabs may not meet that notion.

Similarly, I have a preconceived notion of how a combobox should work,
and neither Spinner nor AutoCompleteTextView meet my notion. The
difference is, I don't claim Android's Spinner and AutoCompleteTextView
are buggy, just because they don't behave quite as I'd like.


You are welcome to write a replacement if the supplied one does not do
what you want, just as there is a myriad of widgets in desktop UI
frameworks that replace OS-supplied ones to overcome various perceived
limitations.

For example, someday, I may craft something closer to my vision of a
combobox.


And the error is...what? Post a traceback from adb logcat, DDMS, or the
Eclipse equivalent, and we may be able to help.

I confess to perhaps jumping the gun on TabHost and kin not working
outside TabActivity. That is definitely the case for
MapView/MapActivity, and I may have drawn an incorrect parallel. Being
short on sleep ain't helping my cognitive faculties... :-(

So, give us some exception information, and let's see if we can solve
your problem.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Published!

--~--~---------~--~----~------------~-------~--~----~



TabHost crash in setup

by Patrick » Wed, 14 Jan 2009 03:15:36 GMT


 Well that will teach me. LogCat did have the answer, but the window
was too small and it clipped the important part of the exception
message, and I only saw it when copy-pasting it here :

Caused by: java.lang.RuntimeException: Your TabHost must have a
TabWidget whose id attribute is 'android.R.id.tabs'

So I guess I am supposed to manually create the two children with
specific IDs. Something to be added to the docs for the next revision
I guess :)

So out of curiosity, if it doesn't create the children views, anyone
know what the call to setup() does?

--~--~---------~--~----~------------~-------~--~----~



TabHost crash in setup

by Mark Murphy » Wed, 14 Jan 2009 03:22:56 GMT


 > So out of curiosity, if it doesn't create the children views, anyone

Here's the TabHost source code:

 http://tinyurl.com/9mpt5e 

Mostly, setup() seems to hook up to various events.

-- 
Mark Murphy (a Commons Guy)
 http://commonsware.com 
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Usability bug report: Poor use of language on failed download report in notification area.

So now it's a bug if someone wants a different choice of words on the
screen for some reason?

I think we need to go back and look at the definition of "bug". This
is not a bug by any stretch of the imagination.

On May 30, 5:02am, "carl.farring...@googlemail.com"


--~--~---------~--~----~------------~-------~--~----~

2. Sharing a native surface between 2 processes

Hello everyone,

I'm researching into the Android graphics and am having problems with
the following scenario:
1. In process A I inherit /SurfaceView/, implement /
SurfaceHolder.Callback/ and override its surfaceCreated() method.
2. Meanwhile I have another process B registering as a binder service
3. When /surfaceCreated(SurfaceHolder holder)/ gets called I extract
the surface from the SurfaceHolder, and pass it to the binder service,
in the remote process.
4. I read the process using /surface->readFromParcel()/

At this point, *in the emulator*, the surface I get in process B is
valid, and I manage to write to the screen just fine.
However, when running this on the device I still get that /surface-
attempting to lock(), Iogcat/ddms shows a "cannot map BpMemoryHeap"
error with EINVAL, and some fd value.

I'm guessing that somehow an fd mapped by the surface's heap is
invalidated when passing the surface via binder,
and that this somehow works in the emulator, since it works with
threads, and not real processes.


Any help would be most appreciated
Thanks,
Mick Halsband

--~--~---------~--~----~------------~-------~--~----~

3. Special characters on hardware keyboard since 1.5 (cupcake)

4. android alarm manager alarm

5. Android - Google Maps - cannot keep map centered?

6. Sending messages to Subactivity( currently running) from the parentActivity

7. my widgets.setOnTouchListener being called twice