簡體   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