• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps regarding TabLayout/Tabwidget

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:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="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:padding="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 :)
 
You can have each tab be a new activity or a just a different view. That's what you did by making your changes -- I'm not sure what your question is.
 
@cp1 - sorry i did not phrase my question correctly.

question 1 - what is the difference between a TabWidget and TabLayout?

question 2- please have a look at my code till strings.xml file (in my previous post) and please (if possible) explain me that why it doesn't work?

the rest of the stuff that i provided after strings.xml is telling what have worked for me , but i was interested in knowing why doesn't my first approach work? and also how can i use the debug tool to figure out what might be going wrong there?

i tried using the debug tool but i got lost after a certain point!

thanks in advance!
 
Is your projects.class a proper activity (defined in your manifest, etc)?

The best way to see what's going wrong is to use DDMS instead of the debugger. See what error it gives you when it crashes.
 
@cp1 - yes i think i have defined Projects.java correctly in my manifest.xml file.
my manifest file looks like this at the moment -

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.sharma"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".androidtab"
android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="Projects"
android:label="projects">
</activity>

</application>
<uses-sdk android:minSdkVersion="7" />

</manifest>

-----

ok let me find how can i use DDMS, if you can please provide some help resourse link for how can i use the DDMS funtionality!

thanks for helping!
 
Projects needs to have either the full name (com.whatever.projects) or it needs a leading period (".Projects").

DDMS is on the top right of the screen (next to Java and Debug). If it's not there, click one of the buttons up there and enable it. I don't have eclipse in front of me, so I can't give more detailed instructions.

Once you switch to the DDMS perspective click the device or emulator that you're running the app in and it will list any error messages. One of the messages will be the file and line number that is causing your crash.
 
Back
Top Bottom