不执行按钮单击事件 [英] Button Click event not performed
本文介绍了不执行按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经写在OnCreate以下code()Activity类的方法
I have write the following code in the onCreate() method of Activity class
Button btn=(Button)findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
Toast.makeText(v.getContext(),"Button Clicked",Toast.LENGTH_LONG).show();
}
});
btn.performClick();
但问题是没有发生在按钮上点击的动作,但如果我点击该按钮后,这个动作被执行。
But the problem is that the action on the button click is not happened, but if I click on that button then this action is performed.
我想通过使用code锁定屏幕,但完全执行的onCreate()方法,
I want to lock the screen by using that code, but it locks after the full execution of onCreate() method,
任何想我怎么能做到这一点。
Any guess how i can do this.
推荐答案
试试这个
final Button backto_main = (Button) findViewById(R.id.back3x3);
backto_main.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//add your code here..
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
Toast.makeText(v.getContext(),"Button Clicked",Toast.LENGTH_LONG).show();
}
});
这篇关于不执行按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文