Button Click Event Not Performed
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()
Solution 1:
try this
final Button backto_main = (Button) findViewById(R.id.back3x3);
backto_main.setOnClickListener(new View.OnClickListener() {
publicvoidonClick(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();
}
});
Solution 2:
My suggestion is
Make a function
by moving the following codes :
privatevoiddoSth(){
WindowManager.LayoutParams params = getWindow().getAttributes();
params.screenBrightness = 0;
getWindow().setAttributes(params);
Toast.makeText(v.getContext(),"Button Clicked",Toast.LENGTH_LONG).show();
}
And instead of doing btn.performClick();
call the function doSth()
in onCreate()
.
and modify your onClickListener
as :
btn.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
doSth();
}
});
This should solve your problem.
Solution 3:
Remove this line:
btn.performClick();
Post a Comment for "Button Click Event Not Performed"