Reputation: 17
I'have a problem. Actually i made a TabActivity with 2 Tabs, when i start it i can change the tab and go to the second one, but when i'm in the second one i can't get back to the first one.
How can that be possible?
Here's my code:
XML:
<TabHost
android:id="@+id/tabHost"
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
android:id="@+id/tab1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:paddingTop="70dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome e Cognome"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eNome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Nome Cognome"
android:inputType="textPersonName" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Categoria segnalazione"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eCategoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
tools:ignore="TextFields" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-mail"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eMail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telefono"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eTel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
</LinearLayout>
<ScrollView
android:id="@+id/tab2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="70dp" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:ignore="ScrollViewSize" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome Azienda"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eAzienda"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nome e Cognome rappresentante"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eRappresentante"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-mail Azienda"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eMailAzienda"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Telefono"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eTelAzienda"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Richiesta"
android:textColor="@color/cWhite" />
<EditText
android:id="@+id/eRichiesta"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.23"
android:ems="10"
android:inputType="textMultiLine"
android:maxLines="3" />
<Button
android:id="@+id/bInvia"
android:layout_width="70dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="@drawable/buttons_back"
android:text="Invia"
android:textColor="@color/cWhite" />
</LinearLayout>
</ScrollView>
</FrameLayout>
</TabHost>
Java:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.lead_comp);
TabHost tabHost = (TabHost) findViewById(R.id.tabHost);
tabHost.setup();
TabSpec spec1 = tabHost.newTabSpec("Tab 1");
spec1.setContent(R.id.tab1);
spec1.setIndicator("Indietro");
TabSpec spec2 = tabHost.newTabSpec("Tab 2");
spec2.setIndicator("Avanti");
spec2.setContent(R.id.tab2);
tabHost.addTab(spec1);
tabHost.addTab(spec2);
Upvotes: 1
Views: 124
Reputation: 1184
I had a similar issue and this post helped me: how to change tab of a tabactivity from an activity started by the tabactivity ? or change current tab
Hope this is along the lines of what you are trying to accomplish.
Also, another suggestion would be to use FragmentActivity. I use this anytime I'm working with tabs. Pretty easy to get a firm grasp on it. There are plenty of examples out there.
Hope one of these helps!
Upvotes: 1