-1
Guys, I’m beginner in android my doubt and the following. I met the Tabhost component and found it very interesting to implement it in the application. The app has a list of restaurants and one chooses the restaurant he opens another acitivity with the menus according to the chosen restaurant, is working but when I choose the restaurant he opens a new Activity and the Tabhost disappears. My question and the following how to open this new Activity inside tabhost(tabspec)? Follow the code:
Tabs:
public class tabs extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.activity_pedido);
// create the TabHost that will contain the Tabs
TabHost tabHost = (TabHost) findViewById(android.R.id.tabhost);
tabHost.setup();
TabSpec tab1 = tabHost.newTabSpec("Aba 1");
tab1.setContent(new Intent(this, lista_restaurantes.class));
tab1.setIndicator("",
getResources().getDrawable(R.drawable.ic_restaurante));
TabSpec tab2 = tabHost.newTabSpec("Aba 2");
tab2.setIndicator("", getResources().getDrawable(R.drawable.ic_promo));
tab2.setContent(new Intent(this, promocoes.class));
TabSpec tab3 = tabHost.newTabSpec("Aba 3");
tab3.setIndicator("",
getResources().getDrawable(R.drawable.ic_carrrinho));
tab3.setContent(new Intent(this, carrinho.class));
/** Add the tabs to the TabHost to display. */
tabHost.addTab(tab1);
tabHost.addTab(tab2);
tabHost.addTab(tab3);
tabHost.setCurrentTab(0);
}
}
He carries the class lista_restaurante
within the TabSpec
public class lista_restaurantes extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lista_restaurantes);
// Hashmap for ListView
restauranteList = new ArrayList<HashMap<String, String>>();
// chama restaurante
new restaurante().execute()
// Cria lista com Vendas no Dia
ListView lv = getListView();
// Quando Selecionar um restaurante
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// OBTEM o valor da ID
String pid = ((TextView) view.findViewById(R.id.pid)).getText()
.toString();
Chama intent com o cardapio de acordo com restaurante
Intent intent = new
Intent(lista_restaurantes.this,lista_caradapio.class);
intent.putExtra(TAG_PID, pid);
Chama a acctivity lista_cardapio
startActivity(intent);
}
});
}
How to call the lista_cardapio.class
within the tabspec?
I found this link http://stackoverflow.com/questions/14213057/android-tabs-open-new-activity-with-every-tab-using-layout-include. I’m going to test!!
– Elmo