New to Android programming, please carry me.
I am trying to open the activity of settings (using general settings) and fill it with those Checkboxesthat are installed or not installed depending on the current settings in the main action.
I managed to get it to work while I put the button in my settings interface , which calls this method to show the status Checkboxesas it is at present.
If I try to call the "settingsLoadSavedSettings" method automatically from the method onCreate, it will not allow me to pass parameters (View view)without the parameters with which the application will work, as soon as it tries to run a line of code .isChecked(true), I think because it cannot be found Checkboxby identifier without parameters.
If I comment out the lines .isChecked(true), the program works correctly if the General privileges are updated , and the main action of the application responds correctly if I click the checkboxes, but Checkboxesgo to the settings user interface, all uncontrolled, regardless of the main application settings at startup.
I am working correctly, except that I need to click the "Show current settings" button in my settings UI after loading the activity to show the current state of the checkboxes. I am trying to automatically populate the status of checkboxes as soon as the activity screen opens.
I left a commented out call in the method onCreate, but I can’t put the view Viewas parameters without the error "Cannot allow display of the character". . Again, settingsLoadSavedSettings works when called by a button in the settings user interface and without View view parameters, when the application starts when you try to open the settings activity.
, . , , - . , , , .
:
public class SettingsActivity extends ActionBarActivity {
CheckBox AllowAddition, AllowSubtraction, AllowMultiplication, AllowDivision;
boolean settingAddition, settingSubtraction, settingMultipliation, settingDivision;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment())
.commit();
}
}
public void settingsLoadSavedSettings(View view){
AllowAddition = (CheckBox) findViewById(R.id.allowAddition);
AllowSubtraction = (CheckBox) findViewById(R.id.allowSubtraction);
AllowMultiplication = (CheckBox) findViewById(R.id.allowMultiplication);
AllowDivision = (CheckBox) findViewById(R.id.allowDivision);
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
settingAddition = sharedPreferences.getBoolean("Allow_Addition",true);
settingSubtraction = sharedPreferences.getBoolean("Allow_Subtraction",true);
settingMultipliation = sharedPreferences.getBoolean("Allow_Multiplication",true);
settingDivision = sharedPreferences.getBoolean("Allow_Division",true);
if (settingAddition){
AllowAddition.setChecked(true);
}
if (settingSubtraction){
AllowSubtraction.setChecked(true);
}
if (settingMultipliation){
AllowMultiplication.setChecked(true);
}
if (settingDivision){
AllowDivision.setChecked(true);
}
}
, onCreate:
02-18 20:55:13.916 24918-24918/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.mathhelper/com.example.mathhelper.SettingsActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
at android.app.ActivityThread.access$700(ActivityThread.java:159)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5419)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)