我已经完成了一个小费计算器应用程序,但是当我运行它时,它的名称是MainActivity
,我不知道如何更改它,我尝试过编辑strings.xml
但是当我运行该应用程序时出现错误,我不知道还能尝试什么,关于我可以做些什么来改变它以便它出现在模拟器上的任何建议
在字符串.xml...
名称:title_activity_main
值:MainActivity
这也是我的java代码我必须在这里改变什么吗?
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);
}
});
}
}
清单.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>
这是我的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>