Back to project page StoichiometryForDummies.
The source code is released under:
GNU Lesser General Public License
If you think the Android project StoichiometryForDummies listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.noahl98.perGProject; //www. j a v a 2 s . c o m import android.R.anim; import android.graphics.Color; import android.os.Bundle; import android.support.v4.app.FragmentActivity; import android.view.View; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class BalancingFragment extends FragmentActivity { TextView title; EditText answer1; EditText answer2; EditText answer3; EditText answer4; EditText answer5; EditText answer6; EditText answer7; @Override public void onCreate(Bundle arg0){ super.onCreate(arg0); setContentView(R.layout.balancing_fragment_layout); //changes the transition overridePendingTransition(R.anim.slide_in_left, R.anim.slide_out_left); //finds view title= (TextView)findViewById(R.id.balancing_title); //changes the font title.setTypeface(LauncherMenu.coolvetica); //finds the EditTexts answer1=(EditText) findViewById(R.id.balancing_answer1); answer2=(EditText) findViewById(R.id.balancing_answer2); answer3=(EditText) findViewById(R.id.balancing_answer3); answer4=(EditText) findViewById(R.id.balancing_answer5); answer5=(EditText) findViewById(R.id.balancing_answer6); answer6=(EditText) findViewById(R.id.balancing_answer7); answer7=(EditText) findViewById(R.id.balancing_answer8); } public void checkAnswer1(View v){ //gets the answers entered into the EditTexts String s1= answer1.getText().toString(); String s2= answer2.getText().toString(); String s3= answer3.getText().toString(); //checks to see if the answer is correct if(s1.equals("2")&&s2.equals("3")&&s3.equals("2")){ Toast.makeText(getApplicationContext(), "Correct!", Toast.LENGTH_LONG).show(); //changes the text color to green answer1.setTextColor(Color.GREEN); answer2.setTextColor(Color.GREEN); answer3.setTextColor(Color.GREEN); }else{ Toast.makeText(getApplicationContext(), "Try Again.", Toast.LENGTH_LONG).show(); //logic for finding the incorrect answers and making them red if(!s1.equals("2")){ answer1.setTextColor(Color.RED); if(s2.equals("3")){ answer2.setTextColor(Color.GREEN); }else{ answer2.setTextColor(Color.RED); } if(s3.equals("2")){ answer3.setTextColor(Color.GREEN); }else{ answer3.setTextColor(Color.RED); } }if(!s2.equals("3")){ answer2.setTextColor(Color.RED); if(s1.equals("2")){ answer1.setTextColor(Color.GREEN); }else{ answer1.setTextColor(Color.RED); } if(s3.equals("2")){ answer3.setTextColor(Color.GREEN); }else{ answer3.setTextColor(Color.RED); } }if(!s3.equals("2")){ answer3.setTextColor(Color.RED); if(s1.equals("2")){ answer1.setTextColor(Color.GREEN); }else { answer1.setTextColor(Color.RED); } if(s2.equals("3")){ answer2.setTextColor(Color.GREEN); }else{ answer2.setTextColor(Color.RED); } } } } public void checkAnswer2(View v){ //gets the text from the edittexts String s1 = answer4.getText().toString(); String s2 = answer5.getText().toString(); String s3 = answer6.getText().toString(); String s4 = answer7.getText().toString(); //checks to see if the answer is correct if((s1.equals("")) && (s2.equals("7/2")) && (s3.equals("2")) && (s4.equals("3"))){ Toast.makeText(getApplicationContext(), "Correct!", Toast.LENGTH_LONG).show(); answer4.setTextColor(Color.GREEN); answer5.setTextColor(Color.GREEN); answer6.setTextColor(Color.GREEN); answer7.setTextColor(Color.GREEN); }else if(s1.equals("2") && s2.equals("7") && s3.equals("4") && (s4.equals("6"))){ Toast.makeText(getApplicationContext(), "Correct!", Toast.LENGTH_LONG).show(); answer4.setTextColor(Color.GREEN); answer5.setTextColor(Color.GREEN); answer6.setTextColor(Color.GREEN); answer7.setTextColor(Color.GREEN); }else { Toast.makeText(getApplicationContext(), "Try Again", Toast.LENGTH_LONG).show(); //logic for finding the incorrect answers and making them red if(!s1.equals("")||!s1.equals("2")){ answer4.setTextColor(Color.RED); if(s2.equals("7/2")||s2.equals("7")){ answer5.setTextColor(Color.GREEN); }else{ answer5.setTextColor(Color.RED); } if(s3.equals("2")||s3.equals("4")){ answer6.setTextColor(Color.GREEN); }else{ answer6.setTextColor(Color.RED); } if(s4.equals("3")||s4.equals("6")){ answer7.setTextColor(Color.GREEN); }else{ answer7.setTextColor(Color.RED); } } if(!s2.equals("7/2")||!s2.equals("7")){ answer5.setTextColor(Color.RED); if(s1.equals("")||s1.equals("2")){ answer4.setTextColor(Color.GREEN); }else{ answer4.setTextColor(Color.RED); } if(s3.equals("2")||s3.equals("4")){ answer6.setTextColor(Color.GREEN); }else{ answer6.setTextColor(Color.RED); } if(s4.equals("3")||s4.equals("6")){ answer7.setTextColor(Color.GREEN); }else{ answer7.setTextColor(Color.RED); } } if(!s3.equals("2")||!s3.equals("4")){ answer6.setTextColor(Color.RED); if(s1.equals("")||s1.equals("2")){ answer4.setTextColor(Color.GREEN); }else{ answer4.setTextColor(Color.RED); } if(s2.equals("7/2")||s2.equals("7")){ answer5.setTextColor(Color.GREEN); }else{ answer5.setTextColor(Color.RED); } if(s4.equals("3")||s4.equals("6")){ answer7.setTextColor(Color.GREEN); }else{ answer7.setTextColor(Color.RED); } } if(!s4.equals("3")||!s4.equals("6")){ answer7.setTextColor(Color.RED); if(s1.equals("")||s1.equals("2")){ answer4.setTextColor(Color.GREEN); }else{ answer4.setTextColor(Color.RED); } if(s2.equals("7/2")||s2.equals("7")){ answer5.setTextColor(Color.GREEN); }else{ answer5.setTextColor(Color.RED); } if(s3.equals("2")||s3.equals("4")){ answer6.setTextColor(Color.GREEN); }else{ answer6.setTextColor(Color.RED); } } } } //shows the correct answer public void showAnswer1(View v){ answer1.setTextColor(Color.BLACK); answer2.setTextColor(Color.BLACK); answer3.setTextColor(Color.BLACK); answer1.setText("2"); answer2.setText("3"); answer3.setText("2"); } //shows the correct answer public void showAnswer2(View v){ answer4.setTextColor(Color.BLACK); answer5.setTextColor(Color.BLACK); answer6.setTextColor(Color.BLACK); answer7.setTextColor(Color.BLACK); answer4.setText(""); answer5.setText("7/2"); answer6.setText("2"); answer7.setText("3"); } @Override public void onPause(){ super.onPause(); //changes the animation when the user navigates away from the page overridePendingTransition(anim.slide_in_left, anim.slide_out_right); } }