Thanks for the link to your book. I have tried your examples from it
and now I get the app forcing to close.
Perhaps you can shed some light on this?
Here's my code:
-- Calculator.java--
package com.calculator;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
public class Calculator extends Activity {
private static final int MY_SETUP = 0;
private static final int MY_ABOUT = 1;
// These are from the layout of the setup menu
RadioButton rb1 = (RadioButton) findViewById(R.id.RadioButton01);
RadioButton rb2 = (RadioButton) findViewById(R.id.RadioButton02);
RadioButton rb3 = (RadioButton) findViewById(R.id.RadioButton03);
RadioButton rb4 = (RadioButton) findViewById(R.id.RadioButton04);
RadioButton rb5 = (RadioButton) findViewById(R.id.RadioButton05);
RadioButton rb6 = (RadioButton) findViewById(R.id.RadioButton06);
EditText ed1 = (EditText) findViewById(R.id.EditText01);
EditText ed2 = (EditText) findViewById(R.id.EditText02);
EditText ed3 = (EditText) findViewById(R.id.EditText03);
EditText ed4 = (EditText) findViewById(R.id.EditText04);
EditText ed5 = (EditText) findViewById(R.id.EditText05);
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// code of the calculator goes here //
}
// options menu
// Called only the first time the options menu is displayed.
// Create the menu entries.
// Menu adds items in the order shown.
public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
menu.add("Setup")
.setIcon(android.R.drawable.ic_menu_preferences);
menu.add("About")
.setIcon(android.R.drawable.ic_menu_info_details);
return(super.onCreateOptionsMenu(menu));
//return true;
}
// handle menu selected
public boolean onOptionsItemSelected(MenuItem item){
if (item.getTitle().equals("Setup")){
Intent intent = new Intent(this,
com.calculator.setup.class);
startActivityForResult(intent, MY_SETUP);
return true;
}
if (item.getTitle().equals("About")){
Intent intent = new Intent(this, com.calculator.about.class);
startActivityForResult(intent, MY_ABOUT);
return true;
}
return(super.onOptionsItemSelected(item));
//return false;
}
}
-- setup (setup.java) --
// code handles radio click & buttons ex: setting default values back
in to the EditText box etc.//
package com.calculator;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
public class setup extends Activity {
public Boolean changeGroup = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dialogsetup);
// code to handle button clicks goes here //
}
}
-- EditPreferences.java --
package com.calculator;
import android.os.Bundle;
import android.preference.PreferenceActivity;
public class EditPreferences extends PreferenceActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
// NOTE: as per your example from your book, this does not have
"import android.app.Activity;" //
// Tried to import, but it would not take //
-- preferences.xml --
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout="@layout/dialogsetup">
// only 1 preference for testing //
<EditTextPreference android:key="@string/ev1"></EditTextPreference>
</PreferenceScreen>
-- strings.xml --
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Calculator</string>
<color name="yellow1">#F2F5A9</color>
<color name="yellow2">#FFFF00</color>
<color name="orange5">#FF8000</color>
<color name="orange6">#F5D0A9</color>
<color name="black1">#000000</color>
<color name="dispBlueDk">#0B0B61</color>
<color name="dispBlueMd">#0000FF</color>
<color name="dispBlueLt">#CECEF6</color>
<color name="bttnNormalGreyDk">#424242</color>
<color name="bttnNormalGreyMd">#848484</color>
<color name="bttnNormalGreyLt">#E6E6E6</color>
<color name="yellow3">#868A08</color>
<color name="white1">#FFFFFF</color>
<color name="bttnTextBlueDk">#08088A</color>
<color name="bttnTextGreenDk">#0B610B</color>
<string name="ev1">30</string>
</resources>
-- manifest.xml --
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.calculator"
android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name"
android:icon="@drawable/calculator">
<activity android:name=".Calculator"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category
android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="setup"></activity>
<activity android:name="about"></activity>
<activity
android:label="@string/app_name"
android:name="EditPreferences">
</activity>
</application>
<uses-sdk android:minSdkVersion="8" />
</manifest>
Other than the screen layouts, that is it.
What could be the error?
On Sep 30, 7:41 pm, Mark Murphy <[email protected]> wrote:
> On Thu, Sep 30, 2010 at 9:15 PM, rb <[email protected]> wrote:
> > I looked at the URL's that you provided and tried some coding with it,
> > but I am failing to understand
> > the proper coding methods.
>
> BTW, the preference chapter in my book has not changed that much from
> earlier editions, so you're welcome to read the relevant chapter in
> the most recent Creative Commons edition:
>
> http://commonsware.com/Android/Android-1_4-CC.pdf
>
> That should give you more context for all of this preference stuff.
>
> --
> Mark Murphy (a Commons
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android Training in Atlanta:http://bignerdranch.com/classes/android
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en