简体   繁体   中英

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 :

 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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