new tab and new activity it's possible? - android

I have three tabs (Tab1, tab 2, tab 3). I want starting the other activity all tabs.
I try the new intent in Tab 2.
My code this
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("Tab 1");
TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2", getResources().getDrawable(R.drawable.ic_launcher));
spec2.setContent(new Intent(this,teszt.class));
TabSpec spec3=tabHost.newTabSpec("Tab 3");
spec3.setIndicator("Tab 3");
spec3.setContent(R.id.tab3);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
}
}
Manifest.xml
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="hu.anzy.fulek.example.fulek.MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".teszt"
></activity>
</application>
Teszt.java
public class teszt extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.teszt_layout);
}
public void onClick(View v){
if (v.getId()== R.id.btnBackTo1){
Toast.makeText(this, "Click BackTo1", Toast.LENGTH_LONG).show();
} else
{
if (v.getId()== R.id.btnStart3) {
Toast.makeText(this, "Click Start3", Toast.LENGTH_LONG).show();
}
}
}
}
Main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tabHost"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<TabWidget
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#android:id/tabs"
/>
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#android:id/tabcontent"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/tab1"
android:orientation="vertical"
android:paddingTop="60px"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="100px"
android:text="This is tab1"
android:id="#+id/txt1"
/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tab2"
android:orientation="vertical"
android:paddingTop="60px"
>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tab3"
android:orientation="vertical"
android:paddingTop="60px"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="100px"
android:text="This is tab 3"
android:id="#+id/txt3"
/>
</LinearLayout>
</FrameLayout>
</TabHost>
Test_layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/btnBackTo1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Back to 1st Activity"
android:onClick="onClick"
/>
<Button
android:id="#+id/btnStart3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Start 3rd Activity"
android:onClick="onClick"
/>
</LinearLayout>
My application is runing but when I selected Tab 2 the application is stop.
What is the problem?

Ok I found the solution.
public class MainActivity extends TabActivity{
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Tab1
TabSpec spec1 = tabHost.newTabSpec("Tab1");
photospec.setIndicator("Tab1");
Intent aIntent = new Intent(this, aActivity.class);
photospec.setContent(aIntent);
// Tab2
TabSpec spec2 = tabHost.newTabSpec("Tab2");
songspec.setIndicator("Tab2");
Intent bIntent = new Intent(this, bActivity.class);
songspec.setContent(bIntent);
// Tab3
TabSpec spec3 = tabHost.newTabSpec("Tab3");
spec3.setIndicator("Tab3");
Intent cIntent = new Intent(this, cActivity.class);
spec3.setContent(cIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(spec1); // Adding tab
tabHost.addTab(spec2); // Adding tab
tabHost.addTab(spec3); // Adding tab
}
}
This aActivity similar bActivity and cActivity
import android.app.Activity;
import android.os.Bundle;
public class aActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.a_layout);
}
}
A_layout.xml similar B_layout.xml and C_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView android:text=" Text"
android:padding="15dip"
android:textSize="18dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
main.xml
<?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">
<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"/>
</LinearLayout>
</TabHost>
manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hu.anzy.example.androidtablayoutactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="hu.anzy.example.MaintActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".aActivity" />
<activity android:name=".bActivity" />
<activity android:name=".cActivity" />
</application>
</manifest>

Related

How to use TabHost with Intent in android studio

I am learning android and i am using android studio ver1.4.1.
I wanna use a Tabhost that has two tabs and each tab content is a class with a layout. but each time i debug the program i got this message :Unfortunately, information has stopped. please help me.
mainActivity.xml:
<TabHost
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/tabs"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
</LinearLayout>
</TabHost>
mainActivity.java:
public class ActivityMain extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity_main);
TabHost tabs = (TabHost) findViewById(R.id.tabs);
tabs.setup();
Intent intentPersonalInfo = new Intent().setClass(this,ActivityPersonalInfo.class);
TabHost.TabSpec spec1 = tabs.newTabSpec("tag1");
spec1.setContent(intentPersonalInfo).setIndicator("Personal Information");
tabs.addTab(spec1);
}
seccondActivity.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/textView"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:layout_marginTop="48dp" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:layout_alignBottom="#+id/textView"
android:layout_alignParentEnd="true"
android:layout_toEndOf="#+id/textView" />
</RelativeLayout>
seccondActivity.java:
public class ActivityPersonalInfo extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(activity_personal_info);
}
manifest:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.miad.information" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme" >
<activity android:name=".ActivityMain" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ActivityPersonalInfo"></activity>
</application>

linked page didn't update in eclipse

I'm implementing an Android app for guitar chord recognition. My first layout xml is fine and it's updated, but when I click on login button it goes to next page and didn't show anything on it.
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/background"
tools:context="com.example.guitarchordrecognition.MainActivity" >
<EditText
android:id="#+id/user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="86dp"
android:ems="10"
android:hint="#string/user" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/user"
android:layout_below="#+id/user"
android:layout_marginTop="30dp"
android:ems="10"
android:hint="#string/pass"
android:inputType="textPassword" />
<Button
android:id="#+id/login"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/password"
android:layout_alignRight="#+id/user"
android:layout_below="#+id/password"
android:layout_marginTop="41dp"
android:text="#string/login"
/>
</lativeLayout>
afterlogin.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/background" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="116dp"
android:text="Button 1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/button1"
android:layout_centerVertical="true"
android:text="Button 2" />
</RelativeLayout>`
Mainactivity.java
public class MainActivity extends ActionBarActivity {
Button mybutton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mybutton = (Button)this.findViewById(R.id.login);
mybutton.setOnClickListener(new View.OnClickListener() {
private void buttonclick()
{
startActivity(new Intent("com.example.guitarchordrecognition.Afterlogin"));
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId())
{
case R.id.login:
buttonclick();
break;
}
}
});
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.guitarchordrecognition"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Afterlogin"
android:label="#string/app_name" >
<intent-filter>
<action android:name="com.example.guitarchordrecognition.Afterlogin" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
I don't know why you use action constructor, but this time
try startActivity(new Intent(MainActivity.this, Afterlogin.class)); instead.

Tabs are not displayed

After adding tabhost and tabcontent can't create tabview.
How to add tab in android. I use below code to display tabs.
XML File:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabHost
android:id="#android:id/tabhost"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/homeLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/dynamicLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Dynamic" />
</LinearLayout>
<LinearLayout
android:id="#+id/staticLinearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Static" />
</LinearLayout>
</FrameLayout>
</TabWidget>
</LinearLayout>
</TabHost>
</LinearLayout>
Java File
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_view);
tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
tabSpec = tabHost.newTabSpec("dynamicTab");
tabSpec.setIndicator("Create Image");
tabSpec.setContent(R.id.dynamicLinearLayout);
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("staticTab");
tabSpec.setIndicator("Select Image");
tabSpec.setContent(R.id.staticLinearLayout);
tabHost.addTab(tabSpec);
tabHost.setCurrentTab(0);
}
Output is:
Can't load two tabs.
Please show where I make a mistake.?
tabSpec = tabHost.newTabSpec("dynamicTab");
tabSpec.setIndicator("Create Image");
tabSpec.setContent(R.id.dynamicLinearLayout);
tabHost.addTab(tabSpec);
tabSpec2 = tabHost.newTabSpec("staticTab");
tabSpec2.setIndicator("Select Image");
tabSpec2.setContent(R.id.staticLinearLayout);
tabHost2.addTab(tabSpec2);
tabHost.setCurrentTab(0);
for java part the answer of sakir is correct you can use it or use mine:
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
TabHost.TabSpec tabSpec = tabHost.newTabSpec("dynamicTab");
tabSpec.setIndicator("Create Image");
tabSpec.setContent(R.id.dynamicLinearLayout);
tabHost.addTab(tabSpec);
TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("staticTab");
tabSpec1.setIndicator("Select Image");
tabSpec1.setContent(R.id.staticLinearLayout);
tabHost.addTab(tabSpec1);
tabHost.setCurrentTab(0);
for your xml part you must remove </TabWidget> and change:
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
to
<TabWidget
android:id="#android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

landscape, portrait

i have been searching this site for an answer but i cant find one . my android app isnt swapping from portrait to landscape in my emulator it just shows a sideways portrait screen.
I have made a layout and layout-land folder with matching xml names and so on . but it doesnt seem to pick up on the layout-land versions. i do not have an onConfig() function or anything so i was wondering if anyone can help???
mainpage.xml layout-land
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/main_background"
android:gravity="center"
android:padding="30dip">
<TextView
android:id="#+id/main_title_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/main_title"
android:textColor="#color/text"
android:textSize="25sp" />
<TableLayout
android:id="#+id/tablelayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:stretchColumns="*">
<TableRow
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<Button
android:id="#+id/start_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/start_button"
android:textColor="#color/text" />
<Button
android:id="#+id/help_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/help_button"
android:textColor="#color/text" />
</TableRow>
<TableRow
android:layout_height="wrap_content"
android:layout_width="match_parent">
<Button
android:id="#+id/extra_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/extra_button"
android:textColor="#color/text" />
<Button
android:id="#+id/stop_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/stop_button"
android:textColor="#color/text" />
</TableRow>
</TableLayout>
</LinearLayout>
LAYOUT
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/main_background"
android:gravity="center"
android:padding="30dip">
<TextView
android:id="#+id/main_title_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/main_title"
android:textColor="#color/text"
android:textSize="25sp" />
<Button
android:id="#+id/start_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/start_button"
android:textColor="#color/text" />
<Button
android:id="#+id/help_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/help_button"
android:textColor="#color/text" />
<Button
android:id="#+id/extra_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/extra_button"
android:textColor="#color/text" />
<Button
android:id="#+id/stop_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/stop_button"
android:textColor="#color/text" />
</LinearLayout>
Manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.MC.ChemPal"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="10" />
<application android:icon="#drawable/icon" android:label="#string/app_name">
<activity android:name=".main"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.MC.ChemPal.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".mainpage" android:label="#string/app_name">
<intent-filter>
<action android:name="com.MC.ChemPal.MAINPAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".Extra"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.MC.ChemPal.EXTRA" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".help"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.MC.ChemPal.HELP" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".search_page"
android:label="#string/app_name">
<intent-filter>
<action android:name="com.MC.ChemPal.SEARCH_PAGE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
java
package com.MC.ChemPal;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class mainpage extends Activity {
/** Called when the activity is first created. */
Button start_button, help_button, extra_button, stop_button;
TextView display;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainpage);
start_button = (Button) findViewById(R.id.start_button);
help_button = (Button) findViewById(R.id.help_button);
extra_button = (Button) findViewById(R.id.extra_button);
stop_button= (Button) findViewById(R.id.stop_button);
display = (TextView) findViewById(R.id.main_title_text);
start_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent openSearchPage = new Intent("com.MC.ChemPal.SEARCH_PAGE");
startActivity(openSearchPage);
}
});
help_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent openHelp = new Intent("com.MC.ChemPal.HELP");
startActivity(openHelp);
}
});
extra_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
Intent openExtra = new Intent("com.MC.ChemPal.EXTRA");
startActivity(openExtra);
}
});
stop_button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
onStop();
}
});
}
}
It is an emulator bug, when you try your activity start in landscape mode you will see that it will load mainpage.xml from layout-land ,
android:screenOrientation="landscape"
but ctrl+f12 doesnt work, it is a bug
http://code.google.com/p/android/issues/detail?id=13189

Android and tabactivity

I have the following example:
When I click on Tab2 the activity doesn't fit between the begining of the android screen and till to the Tabs line. Why? what can I do to try and fit the screen?
Main.java
public class Tabs_androidActivity extends ActivityGroup {
public TabHost mTabHost;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost=(TabHost)findViewById(R.id.tabHost);
tabHost.setup(this.getLocalActivityManager());
TabSpec spec1=tabHost.newTabSpec("Tab 1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("Tab 1");
TabSpec spec2=tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Tab 2");
spec2.setContent(new Intent(this, Tab2.class));
TabSpec spec3=tabHost.newTabSpec("Tab 3");
spec3.setIndicator("Tab 3");
spec3.setContent(R.id.tab3);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
tabHost.addTab(spec3);
tabHost.setCurrentTab(0);
}
}
Tab2.java
public class Tab2 extends Activity {
/** Called when the activity is first created. */
TextView call;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logs);
///....
}
}
and main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/tabHost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" >
<LinearLayout
android:id="#+id/tab1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/tab3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</FrameLayout>
</RelativeLayout>
</TabHost>
logs.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout01"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true" >
</TextView>
</RelativeLayout>
main.xml:
<?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">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"/>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp"/>
</RelativeLayout>
</TabHost>
Your Tab Activity:
public class TabActivity extends android.app.TabActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tab_layout);
// Resources res=getResources();
TabHost tabHost=getTabHost();
TabHost.TabSpec spec;
Intent intent;
intent=new Intent().setClass(this, Tab1Activity.class);
spec=tabHost.newTabSpec("tab1").setIndicator(yourimageID).setContent(intent);
tabHost.addTab(spec);
intent=new Intent().setClass(this, Tab2Activity.class);
spec=tabHost.newTabSpec("tab2").setIndicator(yourimageID).setContent(intent);
tabHost.addTab(spec);
intent=new Intent().setClass(this, Tab3Activity.class);
spec=tabHost.newTabSpec("tab3").setIndicator(yourimageID).setContent(intent);
tabHost.addTab(spec);
tabHost.setCurrentTab(0);
}
}

Categories

Resources