0

My tabhost tools.java:

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabtools);

    Resources res = getResources();
    TabHost tabHost = getTabHost();
    TabHost.TabSpec spec;
    Intent intent;

    // TabDados
    intent = new Intent().setClass(this, ToolDadosTubuCirc.class);
    spec = tabHost.newTabSpec("dados")
            .setIndicator("Dados", res.getDrawable(R.drawable.icondados))
            .setContent(intent);
    tabHost.addTab(spec);
    // TabLegenda
    intent = new Intent().setClass(this, ToolLegendaTubuCirc.class);
    spec = tabHost
            .newTabSpec("legenda")
            .setIndicator("Legenda",
                    res.getDrawable(R.drawable.iconlegenda))
            .setContent(intent);
    tabHost.addTab(spec);
    // TabCalcular
    intent = new Intent().setClass(this, ToolCalcularTubuCirc.class);
    spec = tabHost
            .newTabSpec("calcular")
            .setIndicator("Calcular",
                    res.getDrawable(R.drawable.iconcalcular))
            .setContent(intent);
    tabHost.addTab(spec);
    // TabCorrente
    tabHost.setCurrentTab(0);
}}

Each intent calls an activity. and within each "file. java" commands have to perform the calculations.

Within "dados.java" is where I get the information of the User. When they click on the tab "calcular" must verify that all data has been completed.

I guess I need a "onclicklistener" for each tab, like a button, right??

How? how to create an event to run code when a tab"Dados" tab"Legenda" tab"calcular" is clicked?

Attention: I need to check which tab was clicked from the file "ToolDadosCircular.java."

Edit: tabtools.xml code:

<TabHost
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_above="@+layout/rowLog"
    android:layout_below="@+layout/rowLine" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="5dp" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />

    </LinearLayout>
</TabHost>
GDawson
  • 3
  • 1
  • 6

1 Answers1

0

Try

tabHost.getChildAt(yourtab).setOnClickListener(new View.onClickListener()
{
   @Override public void onClick(View view){
       //your code
   }
}

Edit: I'm guessing your class is like this

public class ToolDadosTubuCirc extends Activity{
    @Override public void onCreate(Bundle bundle){
          //code...
          TabHost tabHost = (TabHost) getParent().findViewById(yourTabHostId);
          //do what you want with tabHost
          //code...
    }
}
Comic Sans MS Lover
  • 1,729
  • 5
  • 26
  • 52
  • work until the problem is the following: click this event I had to do in another class that would be in ToolDadosTubuCirc.java. That is, I can not use the getTabHost, I would have to pass the value of tabHost Tools.java file to another class? If yes, how? – GDawson Apr 16 '12 at 14:26
  • In the other class, use `getParent().getTabHost();` This will get the parent context (TabActivity), and you will be able to access the TabActivity information, such as methods and fields. – Comic Sans MS Lover Apr 16 '12 at 14:30
  • Sorry friend, I don't understand. Could modify your code above to the way it should be when called in my other class? And thanks for the help – GDawson Apr 16 '12 at 14:36
  • the id of my tabhost is the android pattern = "@ android: id / tabhost" and my id is also TabWidget pattern = "@ android: id / tabs" I am not able to do what he said. Do you know how to help me? I edited the above question and added the code from my xml tabhost. – GDawson Apr 16 '12 at 18:10
  • I think you can use the pattern to find your TabHost. `getParent().findViewById(android.R.id.tabhost);` – Comic Sans MS Lover Apr 16 '12 at 18:21
  • more and the code:"tabHost.getChildAt(yourtab).setOnClickListener(new View.onClickListener() ". How do I get my tab? – GDawson Apr 16 '12 at 18:34
  • Well you will be doing `TabHost tabHost = (TabHost) getParent().findViewById(android.R.id.tabhost);` Now just use tabHost to access your tab. You can use the `getCurrentTab` method, from TabHost. – Comic Sans MS Lover Apr 16 '12 at 18:51