How do I change the focus of Tab Tabs?

1

I have the following code.

private void TabsCadastro(int visualizar,int origem)
{
    TabSpec abaCLiente,abaEndereco,abaContrato;
    TabHost tabHost = getTabHost();


    abaCLiente = tabHost.newTabSpec("tag1");
    abaCLiente.setContent(R.id.clientes);
    abaCLiente.setIndicator("Cliente");


    abaEndereco = tabHost.newTabSpec("tag2");
    abaEndereco.setContent(R.id.endereco);
    abaEndereco.setIndicator("Endereço");


    abaContrato = tabHost.newTabSpec("tag3");
    abaContrato.setContent(R.id.contrato);
    abaContrato.setIndicator("Contrato");
    tabHost.setFocusableInTouchMode(true);


    if(origem == 0)
    {
        tabHost.addTab(abaCLiente);
        tabHost.addTab(abaEndereco);
        tabHost.addTab(abaContrato);
    }
    tabHost.getTabWidget().setEnabled(false);

    tabHost.setCurrentTab(0);

}

Would you like to know how to change the focus of the tabs? I would like to create a button to change the focus instead of clicking the tabs for this. I will put a button on each tab to navigate between them already tried to use

    setFocused(boolean),
    setFocusable(boolean),

But I could not change the focus.

    
asked by anonymous 25.12.2014 / 22:35

1 answer

1

I usually do the following:

private void initialiseTabHost(Bundle args) {
    tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();
    AddTab(this, this.tabHost, this.tabHost.newTabSpec("Tab1")
            .setIndicator(addButton("Tab1")));
    AddTab(this, this.tabHost, this.tabHost.newTabSpec("Tab2")
            .setIndicator(addButton("Tab2")));
    AddTab(this, this.tabHost, this.tabHost.newTabSpec("Tab3")
            .setIndicator(addButton("Tab3")));
    tabHost.setOnTabChangedListener(this);
}

public Button addButton(String texto) {
    Button button = new Button(getApplicationContext());
    RelativeLayout.LayoutParams layoutParamsRelative = new RelativeLayout.LayoutParams(
            0, 0);
    button.setLayoutParams(layoutParamsRelative);
    button.setText(texto);
    return button;
}

private void intialiseViewPager() {
    List<Fragment> fragments = new Vector<Fragment>();
    fragments.add(new Fragment1());
    fragments.add(new Fragment2());
    fragments.add(new Fragment3());

    pagerAdapter = new PagerAdapter(super.getSupportFragmentManager(),
            fragments);
    viewPager = (ViewPager) super.findViewById(R.id.viewpager);
    viewPager.setAdapter(pagerAdapter);
    viewPager.setOnPageChangeListener(this);
}
    
07.01.2015 / 11:52