Reaching button in title bar in subactivities

374 Views Asked by At

When creating a titlebar with a button, which is common in all activities e.g. title bar created in tabactivities. how is it possible to reach the button in all of the sub activities??

public class tabActivity extends TabActivity  implements OnClickListener{
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState);
    c = this;
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);

    setContentView(R.layout.tabactivity);

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Settings",
            res.getDrawable(R.drawable.preferences)).setContent(
                    new Intent(this, Settings.class)));

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("About",
            res.getDrawable(R.drawable.newspaper)).setContent(
                    new Intent(this, About.class)));

This is here where i initialize my tabs, and the custom title with buttons..

And in this class i would like to reach the buttons in the custom title.:

public class About extends Activity 
{
@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.about);

    ImageView imag = (ImageView) findViewById(R.id.Position);
    imag.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            System.out.println("heeey");
        }
    });

}

The listener doesnt work??

Hooow is this possible??

2

There are 2 best solutions below

0
On BEST ANSWER
public class tabActivity extends TabActivity{ 
public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState); 
    c = this; 
    requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); 

    setContentView(R.layout.tabactivity); 

    ImageView imag = (ImageView) findViewById(R.id.Position);         
    imag.setOnClickListener(new OnClickListener() {         

    public void onClick(View v) {         
       tabActivity.listener.onClick(v);
    }         

    getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title); 

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("Settings", 
        res.getDrawable(R.drawable.preferences)).setContent( 
                new Intent(this, Settings.class))); 

    mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("About", 
        res.getDrawable(R.drawable.newspaper)).setContent( 
                new Intent(this, About.class))); 
}

public static void setListner(OnClickListener listener)
{
    tabActivity.listner = listener;
}

main activity does not implements eventListener

public class About extends Activity implements OnClickListener
{      
    @Override      
    public void onCreate(Bundle savedInstanceState)       
    {      
        super.onCreate(savedInstanceState);      

        setContentView(R.layout.about);      

    });         

    public void onResume()
    {
        tabActivity.setListener(this);
    }


}      

code goes like this. It's hard to explain

4
On

What is the purpose of that? The event controll is available in main activity.