Clive Jefferies
Clive Jefferies

Reputation: 1158

Custom tabs in Android

I am trying to change the content of the tab header but am struggling. I can see that it is possible to pass a View to the setIndicator() method. I tried this and got a removeParent() warning which I dont understand. Has anyone managed to do this successfully. If so can you explain how you did it please?

Clive

Upvotes: 1

Views: 601

Answers (2)

Amit
Amit

Reputation: 11

This problem occurs when you use the same view in different tabs. You must use a different view. This is what I did:

view.setImageResource(R.drawable.videotab);
view1.setImageResource(R.drawable.musictab);

intent = new Intent().setClass(this, CustomList.class);
spec = tabHost.newTabSpec("Video").setIndicator(view)
.setContent(intent);

tabHost.addTab(spec);


intent = new Intent().setClass(this, CustomListOne.class);
spec = tabHost.newTabSpec("Music").setIndicator(view1)
.setContent(intent);

tabHost.addTab(spec);
tabHost.setCurrentTab(0);

Upvotes: 1

Octavian Helm
Octavian Helm

Reputation: 39604

You don't have to use different Views. You can simply inflate the same layout again when you need it. That means you inflate your layout, set everything you need on your different Views and then you set it as your indicator. If you need another tab just do it again.

Upvotes: 0

Related Questions