繁体   English   中英

android类调用其他活动按钮

[英]android class call other activity button

我可以问问问题:

A.xml有按钮,但是我想用b.class调用a.xml按钮,源代码:

 public Button getButton2() {

       Toast.makeText(view.getContext(), test, Toast.LENGTH_LONG).show();
    return button2;
}

但是当我运行此应用程序时,按钮仍然没有任何响应,是否有错误?

您必须将视图的上下文放入新类。 之后,您可以使用此代码在UI线程中运行它。

((Activity)context).runOnUiThread(new Runnable() {
                 public void run() {
                     // Button stuff here
                 }
             });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM