我在MyApp类中定义了一个全局参数,用于重置所有活动中的一些值,我想为某些checkBoxes和SeekBars设置一些默认值,但是我无法在setOnclickListner()中调用函数setDefaultvarValue.
这是myApp.class的代码:
class MyApp extends Application {
private int setDefault=0;
public int getDeafultVarValue() {
return setDefault;
}
public void setDefaultVarValue(int val) {
setDefault = val;
}
}
和setonClickListner看起来像这样:
Button reset_btn = (Button) rootView.findViewById(R.id.reset_button);
reset_btn.setOnClickListener(new OnClickListener() {
((MyApp) this.getApplication()).setDefaultVarValue(1);
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});