Note that there are some explanatory texts on larger screens.

plurals
  1. POTab Host Activity Example not working in Android
    primarykey
    data
    text
    <p>I have put together a very simple Tab Host demo in Android for learning purposes. It's documented here: <a href="http://www.androidhub4you.com/2013/04/android-tabactivity-tab-layout-demo-tab.html" rel="nofollow">http://www.androidhub4you.com/2013/04/android-tabactivity-tab-layout-demo-tab.html</a></p> <p>I followed the steps as indicated but it's not working. Please help me. My code is:</p> <p><strong>TabhostActivity.java</strong></p> <pre><code> package com.example.tabhostdemo; import android.os.Bundle; import android.app.Activity; import android.app.TabActivity; import android.content.Intent; import android.content.res.Resources; import android.view.Menu; import android.widget.TabHost; public class TabHostActivity extends TabActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_tab_host); Resources res = getResources(); // Resource object to get Drawables TabHost tabHost = getTabHost(); // The activity TabHost TabHost.TabSpec spec; // Reusable TabSpec for each tab Intent intent; // Reusable Intent for each tab // Create an Intent to launch an Activity for the tab (to be reused) intent = new Intent().setClass(this, HomeActivity.class); spec = tabHost.newTabSpec("home") .setIndicator("HOME", res.getDrawable(R.drawable.home1)) .setContent(intent); tabHost.addTab(spec); // Do the same for the other tabs intent = new Intent().setClass(this, AboutActivity.class); spec = tabHost.newTabSpec("about") .setIndicator("ABOUT", res.getDrawable(R.drawable.about1)) .setContent(intent); tabHost.addTab(spec); intent = new Intent().setClass(this, ContactActivity.class); spec = tabHost .newTabSpec("contact") .setIndicator("CONTACT", res.getDrawable(R.drawable.contact1)) .setContent(intent); tabHost.addTab(spec); //set tab which one you want open first time 0 or 1 or 2 tabHost.setCurrentTab(0); } } </code></pre> <p><strong>/Drawable/home.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;!-- When selected --&gt; &lt;item android:drawable="@drawable/home1" android:state_selected="true" /&gt; &lt;!-- When not selected--&gt; &lt;item android:drawable="@drawable/home2" /&gt; &lt;/selector&gt; </code></pre> <p><strong>/Drawable/contact.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;!-- When selected --&gt; &lt;item android:drawable="@drawable/contact1" android:state_selected="true" /&gt; &lt;!-- When not selected--&gt; &lt;item android:drawable="@drawable/contact2" /&gt; &lt;/selector&gt; </code></pre> <p><strong>/Drawable/about.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;selector xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;!-- When selected --&gt; &lt;item android:drawable="@drawable/about1" android:state_selected="true" /&gt; &lt;!-- When not selected--&gt; &lt;item android:drawable="@drawable/about2" /&gt; &lt;/selector&gt; </code></pre>
    singulars
    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.
 

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