从另一活动呼叫按钮 [英] Calling button from another Activity

查看:87
本文介绍了从另一活动呼叫按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编辑按钮从另一个活动?

它返回我的

  java.lang.IllegalStateException:无法执行活动的方法
显示java.lang.NullPointerException:产生的原因
 

当我想

  getButton.setEnabled(假);
 

其中

 按钮getButton =(按钮)findViewById(R.id.buttonGet);
 

解决方案

请确保你调用的setContentView之前,你得到的引用您的按钮,即做到这一点:

 的setContentView(R.layout.my_activity_layout);
 

在这样的:

 按钮getButton =(按钮)findViewById(R.id.buttonGet);
 

How can I edit a button from another Activity?

It returns me an

java.lang.IllegalStateException: Could not execute method of the activity
Caused by: java.lang.NullPointerException

When I want to

getButton.setEnabled(false);

where

Button getButton = (Button)findViewById(R.id.buttonGet);

解决方案

Make sure you have called setContentView before you get a reference to your button, i.e do this:

setContentView(R.layout.my_activity_layout);

before this:

Button getButton = (Button)findViewById(R.id.buttonGet);

这篇关于从另一活动呼叫按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆