learning_intern
Newbie
Hi, firstly i would like to know what is the difference between a TabLayout and a Tabwidget? i have an impression that they are the same thing but i may be wrong. the reason for me saying this is because the tutorials for both of them are similar. -
TabWidget - Hello, TabWidget | Android Developers
TabLayout - Tab Layout | Android Developers
--------
besides this confusion, I got another question, i am trying to display text in a tab by creating TextView tags in the main.xml file.
my project is called android_tab, and my android_tab.java file looks like -
package learning.androidtab;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class androidtab extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources(); //Resource object to get the drawables (the tab icons here)
TabHost tab_host = getTabHost(); // the activity TabHost
TabHost.TabSpec spec;
Intent intent; // reusable Intent for each tab
//Creating an Intent to launch an Activity for the tab
intent = new Intent().setClass(this, Projects.class);
spec = tab_host.newTabSpec("projects").setIndicator("Projects",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tab_host.addTab(spec);
tab_host.setCurrentTab(0);
}
}
-----
and my projects.java file looks like -
package learning.androidtab;
import android.app.Activity;
import android.os.Bundle;
public class Projects extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.id.projectsview);
}
}
------
and my main.xml file looks like -
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android
rientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android
adding="5dp" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android
adding="5dp">
<TextView
android:id="@+id/projectsview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/projects_info" />
</FrameLayout>
</LinearLayout>
</TabHost>
-------------
and my strings.xml file looks like -
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="projects_info">this is the tab for projects info</string>
<string name="app_name">androidTabs</string>
</resources>
---------
i am able to display the text on my tab when in my android_tab.java file i replace -
"spec = tab_host.newTabSpec("projects").setIndicator("Projects",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);"
with
spec = tab_host.newTabSpec("projects").setIndicator("Projects",res.getDrawable(R.drawable.ic_tab_artists)).setContent(R.id.projectsview);
-----
and also if i make a projects_view.xml file in my layout folder which looks like this -
<?xml version = "1.0" encoding = "utf-8"?>
<TextView xmlns:android = "http://schemas.android.com/apk/res/android"
android:id="@+id/projview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/projects_info" />
and then without making any changes in the android_tab.java file, i make a change in the Pojects.java file by replacing -
setContentView(R.id.projectsview);
by
setContentView(R.layout.projects_view);
----------
can some one help me out with this?
thanks in advance
TabWidget - Hello, TabWidget | Android Developers
TabLayout - Tab Layout | Android Developers
--------
besides this confusion, I got another question, i am trying to display text in a tab by creating TextView tags in the main.xml file.
my project is called android_tab, and my android_tab.java file looks like -
package learning.androidtab;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.widget.TabHost;
public class androidtab extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Resources res = getResources(); //Resource object to get the drawables (the tab icons here)
TabHost tab_host = getTabHost(); // the activity TabHost
TabHost.TabSpec spec;
Intent intent; // reusable Intent for each tab
//Creating an Intent to launch an Activity for the tab
intent = new Intent().setClass(this, Projects.class);
spec = tab_host.newTabSpec("projects").setIndicator("Projects",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);
tab_host.addTab(spec);
tab_host.setCurrentTab(0);
}
}
-----
and my projects.java file looks like -
package learning.androidtab;
import android.app.Activity;
import android.os.Bundle;
public class Projects extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.id.projectsview);
}
}
------
and my main.xml file looks like -
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android

android:layout_width="fill_parent"
android:layout_height="fill_parent"
android

<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android

<TextView
android:id="@+id/projectsview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/projects_info" />
</FrameLayout>
</LinearLayout>
</TabHost>
-------------
and my strings.xml file looks like -
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="projects_info">this is the tab for projects info</string>
<string name="app_name">androidTabs</string>
</resources>
---------
i am able to display the text on my tab when in my android_tab.java file i replace -
"spec = tab_host.newTabSpec("projects").setIndicator("Projects",res.getDrawable(R.drawable.ic_tab_artists)).setContent(intent);"
with
spec = tab_host.newTabSpec("projects").setIndicator("Projects",res.getDrawable(R.drawable.ic_tab_artists)).setContent(R.id.projectsview);
-----
and also if i make a projects_view.xml file in my layout folder which looks like this -
<?xml version = "1.0" encoding = "utf-8"?>
<TextView xmlns:android = "http://schemas.android.com/apk/res/android"
android:id="@+id/projview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@string/projects_info" />
and then without making any changes in the android_tab.java file, i make a change in the Pojects.java file by replacing -
setContentView(R.id.projectsview);
by
setContentView(R.layout.projects_view);
----------
can some one help me out with this?
thanks in advance
