java,android,final Button btn = (Button) findViewById../这个btn为啥要是final类型的才正确呢??
packagecom.example.exp3_28_1;importandroid.app.Activity;importandroid.os.Bundle;impor...
package com.example.exp3_28_1;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CheckBox ch = (CheckBox) findViewById(R.id.checkBox1);
final Button btn = (Button) findViewById(R.id.button1);/////这个btn为啥要是final类型的才正确呢??
btn.setEnabled(false);
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked)
btn.setEnabled(true); ///////这个btn为啥要是final类型的才正确呢??
else
btn.setEnabled(false);
}
});
}
} 展开
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
CheckBox ch = (CheckBox) findViewById(R.id.checkBox1);
final Button btn = (Button) findViewById(R.id.button1);/////这个btn为啥要是final类型的才正确呢??
btn.setEnabled(false);
ch.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked)
btn.setEnabled(true); ///////这个btn为啥要是final类型的才正确呢??
else
btn.setEnabled(false);
}
});
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询