The functionality of my program is not working properly. It is not doing what I need it to do. I don't have any errors in the code but the app isn't doing what I want it to do.
**UPDATE: Okay thank you very much for the help. the button displays a value for TextView ce. However, the app does not seem to run my ifstatement to get a new value of CE1 which would be = 4*credit_1. The app is taking the initialized value of CE1 which is = 0, and converting that to a string CE1s. Hence dispalying 0.0 in TextView ce. Why is the app not taking my ifstatement if(grade_1.equals("A")) into consideration?
Here is the MainActivity.java:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText course1 = (EditText)findViewById(R.id.Course1);
EditText credit1 = (EditText)findViewById(R.id.editText7);
final EditText grade1 = (EditText)findViewById(R.id.editText13);
final Button b = (Button)findViewById(R.id.button1);
final TextView ce = (TextView)findViewById(R.id.textView5);
String grade_1 = grade1.getText().toString();
String text = credit1.getText().toString();
if (!TextUtils.isEmpty(text)) {
// call parseDouble in here
double credit_1 = Double.parseDouble(text);
double CE1=0;
if (grade_1 =="A")
CE1 = 4*credit_1;
final String CE1s = Double.toString(CE1);
b.setOnClickListener(new OnClickListener(){
public void onClick(View v){
ce.setText(CE1s);
}
});
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
}
}
Here is the AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.rutgersgpacalculator"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.rutgersgpacalculator.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>
</application>
</manifest>