【问题标题】:How to make button click from an static method in android如何从android中的静态方法单击按钮
【发布时间】:2012-10-10 04:43:12
【问题描述】:

我有一个“提交”按钮,我想在静态方法中创建“submit.performclick”,我试过但我不能,帮助我克服这个问题,还有一件事,在那个点击动作中,可能有是任何非静态方法.. 但我想点击按钮。

 new_btn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            CallingDataBase("fm Btn","from button");
            ClearMemory();
        }
    });
public void CallingDataBase(String mobileNumber, String mobileMessage)
{
        us = mobileNumber;
        pa = mobileMessage;
        insertion(us,pa);
        CallingCustomAdapter();
}

//this static method was the first calling method.
  public static void updateMessageBox(String mobileNum12, String mobileMessa12,Context context)
//I get parameters for this method from another class.
{   

//      SMS smsClass = new SMS();    // SMS was my Class Name`
//      smsClass.function(context);
//       from here i want to call button action   


}

【问题讨论】:

  • 请粘贴您尝试过的代码..
  • 帮我解决这个问题。我已经粘贴了我的代码。

标签: android android-activity click static-methods non-static


【解决方案1】:

您可以通过以下方式为静态方法提供对按钮的引用作为参数:

//this static method was the first calling method.
public static void updateMessageBox( Button button , String mobileNum12, String mobileMessa12,Context context)
//I get parameters for this method from another class.
{   

//      SMS smsClass = new SMS();    // SMS was my Class Name`
//      smsClass.function(context);
//       from here i want to call button action   
button.performClick();

}

【讨论】:

    猜你喜欢
    • 2015-05-30
    • 1970-01-01
    • 2012-05-15
    • 2015-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-12
    相关资源
    最近更新 更多