Reputation: 3
I have 2 activities, The first activity consist of two buttons that goes to the second activity.
The second activity consists of 2 tab host.
I want to enable the 2nd tabhost from the button of the first activity. how can i do that, please help me and thank you... ^_^
The First Activity Code:
public void OnClickRanoNews(View v)
{
if (v.getId() == R.id.btnRanoNews)
{
Intent i = new Intent(this, RanoNews.class);
startActivity(i);
}
}
public void OnClickRanoNews2(View v)
{
if(v.getId()== R.id.btnRanoNews2)
{
Intent i = new Intent(this, RanoNews.class);
startActivity(i);
//I want to disable the second tabhost in this button
}
}
The Second Activity Code:
tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec
tabSpec = tabHost.newTabSpec("rano news");
tabSpec.setContent(R.id.tabRanoNews);
tabSpec.setIndicator("Rano News");
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("adding form");
tabSpec.setContent(R.id.tabAddingForm);
tabSpec.setIndicator("Adding Form");
tabHost.addTab(tabSpec);
tabHost.getTabWidget().getChildTabViewAt(1).setEnabled(true);
Upvotes: 0
Views: 345
Reputation: 3
This is what i do to the First Activity Code:
public void OnClickRanoNews(View v)
{
if (v.getId() == R.id.btnRanoNews)
{
Intent i = new Intent(this, RanoNews.class);
i.putExtra("msg","0");
startActivity(i);
}
}
public void OnClickRanoNews2(View v)
{
if(v.getId()== R.id.btnRanoNews2)
{
Intent i = new Intent(this, RanoNews.class);
i.putExtra("msg","1");
startActivity(i);
}
}
Second Activity Code:
tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec
tabSpec = tabHost.newTabSpec("rano news");
tabSpec.setContent(R.id.tabRanoNews);
tabSpec.setIndicator("Rano News");
tabHost.addTab(tabSpec);
tabSpec = tabHost.newTabSpec("adding form");
tabSpec.setContent(R.id.tabAddingForm);
tabSpec.setIndicator("Adding Form");
tabHost.addTab(tabSpec);
if(getIntent()!=null)
{
if(getIntent().getStringExtra("msg").equals("0"))
tabHost.getTabWidget().getChildTabViewAt(1).setEnabled(true);
else if (getIntent().getStringExtra("msg").equals("1"))
tabHost.getTabWidget().getChildTabViewAt(1).setVisibility(View.GONE);
}
Upvotes: 0
Reputation: 6356
Just pass additional extra parameter to new activity (in Bundle)
if (v.getId() == R.id.btnRanoNews2) {
Intent i = new Intent(this, RanoNews.class);
i.putExtra(RanoNews.TABHOST_ENABLED, false /* put your value here */);
startActivity(i);
}
And handle it in new activity as last line of onCreate()
method
public static final String TABHOST_ENABLED = "tabhost_enabled";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* TabHost initialization */
if (getIntent().getExtras() != null) {
boolean isEnabled = getIntent().getExtras().getBoolean(TABHOST_ENABLED);
tabHost.setEnabled(isEnabled);
}
}
Upvotes: 0
Reputation:
public void OnClickRanoNews2(View v)
{
if(v.getId()== R.id.btnRanoNews2)
{
Intent i = new Intent(this, RanoNews.class);
i.putExtra("msg", "0");
startActivity(i);
}
}
on the second Activity
if(getIntent() != null){
if(getIntent().getStringExtra("msg").equals("0")){
tabHost.getTabWidget().getChildTabViewAt(1).setEnabled(true);
}
}
Upvotes: 1