This is my code for tabs. Kindly tell me how to put listener on tab1 either through switch statement or by simple onclick listener. And this toast message is also not working
public class TabsActivity extends Activity implements OnClickListener {
TabHost th;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tabs);
th = (TabHost)findViewById(R.id.tabhost);
th.setup();
TabSpec specs = th.newTabSpec("tag1");
specs.setContent(R.id.tab1);
specs.setIndicator("Home");
th.addTab(specs);
specs = th.newTabSpec("tag2");
specs.setContent(R.id.tab2);
specs.setIndicator("Goup");
th.addTab(specs);
specs = th.newTabSpec("tag3");
specs.setContent(R.id.tab3);
specs.setIndicator("Delete");
th.addTab(specs);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
switch(arg0.getId()){
case R.id.tab1:
Toast.makeText(TabsActivity.this, "Action Item 0 selected!", Toast.LENGTH_LONG).show();
break;
case R.id.tab2:
TextView text= new TextView(TabsActivity.this);
text.setText("u have created a new tab");
break;
case R.id.tab3:
break;
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_tabs, menu);
return true;
}
}