Buenas a ver si podeis ayudarme un poquillo , soy nueva en este foro, y tambien llevo poco tiempo programando en Android , basicamente he hecho el HolaMundo y dos tonterias mas ; Ahora estoy haciendo una aplicacion con tabhost para Android 4.2, tiene tres pestañas , he conseguido saber en que pestaña estoy , pero no logro cargar lo que quiero en cada pestaña . De momento solo lo he intentando con la pestaña dos , añadiendola una caja de texto, pero siempre aparece cargada la caja de texto , da igual la pestaña que selecciones , y cuando pulso la pestada dos , desaparecen el resto de pestañas. Cuando pulso la pestaña dos llamo a otra Activity que carga el Linearlayaout(id/tab1). que contiene el txt.
Muchas gracias
el codigo de mi layout es este:
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".PortadaActivity"
tools:ignore="MergeRootFrame" >
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
android:layout_height="match_parent"
android:orientation="vertical" >
android:layout_width="match_parent"
android:layout_height="wrap_content" >
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_width="fill_parent"
android:text="Pestaña dos">
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:layout_width="match_parent"
android:layout_height="match_parent" >
Codigo de las dos activities:
Principal :
Public class PortadaActivity
ActionBar.TabListener {
/**
* The serialization (saved instance state) Bundle key representing the
* current tab position.
*/
private static final String STATE_SELECTED_NAVIGATION_ITEM = "selected_navigation_item";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.portada);
// Set up the action bar to show tabs.
final ActionBar actionBar = getActionBar();
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
// For each of the sections in the app, add a tab to the action bar.
actionBar.addTab(actionBar.newTab().setText(R.string.title_section1)
.setTabListener(this));
actionBar.addTab(actionBar.newTab().setText(R.string.title_section2)
.setTabListener(this));
actionBar.addTab(actionBar.newTab().setText(R.string.title_section3)
.setTabListener(this));
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState) {
// Restore the previously serialized current tab position.
if (savedInstanceState.containsKey(STATE_SELECTED_NAVIGATION_ITEM)) {
getActionBar().setSelectedNavigationItem(
savedInstanceState.getInt(STATE_SELECTED_NAVIGATION_ITEM));
}
}
@Override
public void onSaveInstanceState(Bundle outState) {
// Serialize the current tab position.
outState.putInt(STATE_SELECTED_NAVIGATION_ITEM, getActionBar()
.getSelectedNavigationIndex());
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.portada, menu);
return true;
}
@Override
public void onTabSelected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
// When the given tab is selected, show the tab contents in the
// container view.
int numTab= tab.getPosition();
if (numTab == 0){
Toast.makeText(getApplicationContext(), "CERO", Toast.LENGTH_SHORT).show();
}else if (numTab==1){
Intent intent = new Intent(PortadaActivity.this, tab1.class);
Bundle bundle = new Bundle();
intent.putExtras(bundle);
startActivity(intent);
}else if (numTab==2){
Toast.makeText(getApplicationContext(), "DOS", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onTabUnselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
@Override
public void onTabReselected(ActionBar.Tab tab,
FragmentTransaction fragmentTransaction) {
}
/**
* A dummy fragment representing a section of the app, but that simply
* displays dummy text.
*/
public static class DummySectionFragment extends Fragment {
/**
* The fragment argument representing the section number for this
* fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
public DummySectionFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Create a new TextView and set its text to the fragment's section
// number argument value.
TextView textView = new TextView(getActivity());
textView.setGravity(Gravity.CENTER);
textView.setText(Integer.toString(getArguments().getInt(
ARG_SECTION_NUMBER)));
return textView;
}
}
}
Activity pestaña 2 :
public class tab1 extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.portada);
LinearLayout tab1 = (LinearLayout) findViewById(R.id.tab1);
}
}