Note that there are some explanatory texts on larger screens.

plurals
  1. POInflating multiple instances of the same layout into tabs
    primarykey
    data
    text
    <p>This is a problem that has troubled me for a few days now. I've done my best searching for a solution, but everywhere I go it says the approach I'm currently using is the right one.</p> <p>The situation is simple: I have five tabs, which are to contain the same layout with slightly different content (for example by using setText to change one of the labels). As such, I am inflating the layout five times, and adding all of them as seperate tabs.</p> <p>This is my code:</p> <pre><code>package com.test; import android.app.TabActivity; import android.content.res.Resources; import android.os.Bundle; import android.view.View; import android.widget.TabHost; import android.widget.TextView; public class TestActivity extends TabActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); TabHost host = getTabHost(); Resources res = getResources(); String[] days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" }; for (int i = 0; i &lt; days.length; i++) { View contents = getLayoutInflater().inflate(R.layout.test, host.getTabContentView(), true); ((TextView)contents.findViewById(R.id.title)).setText(days[i]); host.addTab ( host.newTabSpec(days[i]). setIndicator(days[i]). setContent(contents.getId()) ); host.getTabWidget().getChildAt(i).getLayoutParams().height = 55; } } } </code></pre> <p>And my layout file looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="6dip"&gt; &lt;TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Test" android:textAppearance="?android:attr/textAppearanceMedium" /&gt; &lt;/LinearLayout&gt; </code></pre> <p>The problem is that, instead of the text being on seperate tabs, all the text overlaps eachother and is the same for every tab. It might be something really simple that I'm overlooking. Any help is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload