简体   繁体   English

android类调用其他活动按钮

[英]android class call other activity button

May I ask Quesion: 我可以问问问题:

A.xml have button, but I want use b.class call a.xml button, source code : A.xml有按钮,但是我想用b.class调用a.xml按钮,源代码:

 public Button getButton2() {

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

But when I running this app, button still didn't have any response, is have any wrong? 但是当我运行此应用程序时,按钮仍然没有任何响应,是否有错误?

You have to put the context of the view to the new class. 您必须将视图的上下文放入新类。 After that you can use this code, to run it in the UI thread. 之后,您可以使用此代码在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