1

I have finished a tip calculator app, but when I run it the name is MainActivity, I don't know how to change it, I have tried editing strings.xml but when I run the app I get errors,I don't know what else to try, any suggestions for what I can do to change it so it appears on the emulator

on strings.xml...

name:title_activity_main value:MainActivity

also here is my java code will i have to change anything here?

package tip.calculator;


import android.os.Bundle;
import android.app.Activity;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.TextView;
import android.view.View;
import android.widget.Button;
import java.text.DecimalFormat;

public class TipCalculator extends Activity 
{
private EditText myEditField;
private EditText myEditField2;
private Button enter;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    myEditField2 = (EditText) findViewById(R.id.billText);
    myEditField = (EditText) findViewById(R.id.percentText);
    enter = (Button)findViewById(R.id.button1);

    enter.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            TextView textView;

            textView = (TextView) findViewById(R.id.textView1);

            final EditText myEditField = (EditText) findViewById(R.id.percentText);
            final EditText myEditField2 = (EditText) findViewById(R.id.billText);

            float percentage;
            float percentageInp;
            float billAmount;
            double output; 
            String output1;

            percentageInp = Float.parseFloat(myEditField.getText().toString());
            billAmount = Float.parseFloat(myEditField2.getText().toString());

            percentage = ((float)percentageInp /100);

            output = (double)(billAmount * percentage);

            double result = output * 100;
            result = Math.round(result);
            result = result / 100;

            output1 = Double.toString(result);

            textView.setText(output1);

        }
    });
}
}

manifest.xml ...

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tip.calculator"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" android:debuggable="true">
        <activity
            android:name=".TipCalculator"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

here is my strings.xml

<resources>

    <string name="app_name">Tip Calculator</string>
    <string name="hello_world">Hello world!</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_main">MainActivity</string>

</resources>
kablu
  • 629
  • 1
  • 7
  • 26
PrommeringsDisplay
  • 99
  • 1
  • 2
  • 12

3 Answers3

4

change the label

android:label="Tip Calculator"

or change your strings.xml

<string name="app_name">Tip Calculator</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_main">Tip Calculator</string>

Niko Adrianus Yuwono
  • 11,012
  • 8
  • 42
  • 64
3

This is because android does not allow for two different labels for the app_name and main activity name. But in case you want to use two different labels at the same time you could accomplish it as follow;

The name for your App to be shown on app menu

<application> android:lable = "@string/app_name" </application>

And the different label when you launch the activity;

in your onCreate() method of the main activity put;

this.setTitle("Your Title for the Activity");
ssrp
  • 1,126
  • 5
  • 17
  • 35
0

Thats just an error in eclipse sometimes, close eclipse then clean your project and it should be fine

eoghanm
  • 329
  • 1
  • 9