
android代码如下,点击check后,运行提示错误,求指教!
publicclassFirstextendsActivity{privateEditTextedit=null;privateCheckBoxcheck=null;pr...
public class First extends Activity{
private EditText edit=null;
private CheckBox check=null;
protected void onCreate(Bundle savedInstancestate){
super.onCreate(savedInstancestate);
setContentView(R.layout.first_layout);
EditText edit=(EditText) findViewById(R.id.edit);
CheckBox check=(CheckBox) findViewById(R.id.check);
check.setOnClickListener(new OnClickListenerlmpl());
}
private class OnClickListenerlmpl implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (check.isChecked()){
edit.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
edit.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
}
} 展开
private EditText edit=null;
private CheckBox check=null;
protected void onCreate(Bundle savedInstancestate){
super.onCreate(savedInstancestate);
setContentView(R.layout.first_layout);
EditText edit=(EditText) findViewById(R.id.edit);
CheckBox check=(CheckBox) findViewById(R.id.check);
check.setOnClickListener(new OnClickListenerlmpl());
}
private class OnClickListenerlmpl implements OnClickListener{
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if (check.isChecked()){
edit.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}else{
edit.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
}
} 展开
2个回答
展开全部
private EditText edit=null;
private CheckBox check=null;
你这里已经定义过这2个成员变量了。
在orCreat方法中EditText edit=(EditText) findViewById(R.id.edit);
CheckBox check=(CheckBox) findViewById(R.id.check);又定义了2个。
这实际就是new出来2个对象了
你把orCreat方法中修改成
edit=(EditText) findViewById(R.id.edit);
check=(CheckBox) findViewById(R.id.check);
就可以了
private CheckBox check=null;
你这里已经定义过这2个成员变量了。
在orCreat方法中EditText edit=(EditText) findViewById(R.id.edit);
CheckBox check=(CheckBox) findViewById(R.id.check);又定义了2个。
这实际就是new出来2个对象了
你把orCreat方法中修改成
edit=(EditText) findViewById(R.id.edit);
check=(CheckBox) findViewById(R.id.check);
就可以了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询