到达子活动中标题栏中的按钮

发布于 2024-12-29 12:58:21 字数 1403 浏览 1 评论 0原文

创建带有按钮的标题栏时,这在所有活动中都很常见,例如在选项卡活动中创建的标题栏。如何才能到达所有子活动中的按钮?

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

这是我初始化选项卡和带有按钮的自定义标题的地方。

在这个类中,我想访问自定义标题中的按钮。:

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

}

侦听器不起作用?

呼这可能吗?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

纵情客 2025-01-05 12:58:21
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;
}

主活动没有实现 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);
    }


}      

代码是这样的。很难解释

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

白色秋天 2025-01-05 12:58:21

这样做的目的是什么?事件控件在主活动中可用。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文