-
-
Save realdm/0d708a8cf483eaa24bfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.app.mungoi.minhaprimeiraapp; | |
import android.support.v4.app.FragmentTransaction; | |
import android.support.v7.app.ActionBarActivity; | |
import android.os.Bundle; | |
import android.view.Menu; | |
import android.view.MenuItem; | |
import android.widget.FrameLayout; | |
public class MainActivity2 extends ActionBarActivity { | |
/** Framelayout que ira conter o tablet caso seja um smartphone*// | |
private FrameLayoutLayout mContainer; | |
private Fragment mFragment; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main_activity); | |
mContainer = (FrameLayout) findViewById(R.id.container); | |
if(mContainer==null) | |
{ | |
//O xml carregado nao contem nenhum framelayout logo estamos a correr a aplicacao de um tablet | |
//serao apresentados dois paineis | |
} | |
else | |
{ | |
//estamos no layout do celular devemos colocar o primeiro fragment no container | |
mFragment = new FragmentA(); | |
//Pegar um Fragment Transaction responsavel por adicionar, modificar e remover fragments | |
FragmentTransaction mFragmentTrasaction = getSupportFragmentManager().beginTransaction(); | |
/**Adiciona um fragment passando o id do container(FrameLayout), o fragment, e uma tag opcional para poder identificar o fragment posteriormente | |
* | |
*/ | |
mFragmentTrasaction.add(R.id.container,mFragment); | |
//E sempre importante fazer o commit para que as mudancas seja efectuadas caso nao todo codigo acima nao tera nenhum efeito | |
mFragmentTrasaction.commit(); | |
} | |
} | |
@Override | |
public boolean onCreateOptionsMenu(Menu menu) { | |
// Inflate the menu; this adds items to the action bar if it is present. | |
getMenuInflater().inflate(R.menu.menu_main_activity2, menu); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment