如何从活动中禁用标签?

时间:2015-09-18 11:03:22

标签: android android-tabhost

我有2项活动, 第一个活动包括两个进入第二个活动的按钮。

第二个活动包含2个标签主机。

我想从第一个活动的按钮启用第二个tabhost。我怎么能这样做,请帮帮我,谢谢...... ^ _ ^

第一个活动代码:

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
        }
}

第二个活动代码:

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);

3 个答案:

答案 0 :(得分:1)

public void OnClickRanoNews2(View v)
{
        if(v.getId()== R.id.btnRanoNews2)
        {
            Intent i = new Intent(this, RanoNews.class); 
            i.putExtra("msg", "0");
            startActivity(i);
        }
} 

关于第二个活动

if(getIntent() != null){
      if(getIntent().getStringExtra("msg").equals("0")){
         tabHost.getTabWidget().getChildTabViewAt(1).setEnabled(true);
     }
}

答案 1 :(得分:0)

只需将额外的额外参数传递给新活动(在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);
    }

并在新活动中将其作为onCreate()方法

的最后一行处理
    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);
        }
    }

答案 2 :(得分:0)

这就是我对第一个活动代码所做的事情:

Sub ProcessFiles()
Dim Filename, Pathname, SaveFileName As String
Dim wb As Workbook

Pathname = "C:\Users\user\Desktop\test\"
Filename = Dir(Pathname & "*.xls")
Application.DisplayAlerts = True

Do While Filename <> ""
    Set wb = Workbooks.Open(Pathname & Filename)
    wb.CheckCompatibility = True
    saveFileName = Replace(Filename, ".xls", ".xlsx")

    wb.SaveAs Filename:=saveFileName

    wb.Close SaveChanges:=True
    Filename = Dir()
Loop
Application.DisplayAlerts = True
End Sub

第二个活动代码:

A40's RGB= 0, 154, 61
A41's RGB= 146, 208, 80
A42's RGB= 255, 210, 0
A43's RGB = 227, 27, 35
A44's RGB= 191, 232, 255
A45's RGB= 200, 200, 200
A46 has no color