I am very new to Android app programming and am trying to get a handle on some concepts through a simple calculator program that will contain a lot of useless features. Basically i have two EditText's (to enter two numbers) and a RadioGroup (to select the math operation to be performed on the numbers) in the main activity and I display the total in a child activity. This all works great. My problem is that when I hit the up button, I want the total to be displayed as the first EditText's hint in the MainActivity. Basically allowing the user to carry on a string of simple calculations without having to reenter the previous total. (the hint values are used if the EditText is left empty) I have tried onNavigateUpFromChild(Activity child)
, but to no avail. Is this even possible?
Here is my code thus far.
MainActivity.java:
public class MainActivity extends Activity {
//! Irrelevant code removed !//
/** Variable Declaration */
Float total; // Holds a running total
EditText num1; // Text box for first number
//! Irrelevant code removed !//
@Override
public boolean onNavigateUpFromChild(Activity child) {
num1.setHint(total.toString());
return onNavigateUp();
}
//! Irrelevant code removed !//
}
DisplayTotalActivity.java:
public class DisplayTotalActivity extends Activity {
//! Irrelevant code removed !//
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mdiehl.calculator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="16"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.mdiehl.calculator.MainActivity"
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="com.mdiehl.calculator.DisplayTotalActivity"
android:label="@string/title_activity_display_total"
android:parentActivityName="com.mdiehl.calculator.MainActivity"
android:theme="@android:style/Theme.Holo" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mdiehl.calculator.MainActivity" />
</activity>
</application>
</manifest>
As far as I can tell, the onNavigateUpFromChild method is never even called.
Thanks in advance to anyone that can offer some assistance in this matter.