I am trying to create a simple grade tracker for android. The way I have it set up is that the user has a list of classes that are in their major. When they click on the title of the class, a new activity starts that has the name of the class, the catalog description, a space to place your grade, and a button to return to the list of classes.
What I would like to do is save the grade number that they input on the second page, and when the button is pressed, on the first page the grade is shown next to the course title.
I have edited to the code to reflect the comments given. This is the code that works!
CoreClasses
TextView eng101, eng101scr;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.classcore);
eng101 = (TextView)findViewById(R.id.eng101);
eng101scr = (TextView)findViewById(R.id.eng101CoreScr);
eng101.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(ClassCore.this, Eng101.class);
i.putExtra("grades", "eng101" );
startActivityForResult(i, 1);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if(data.getExtras().containsKey("e101FinalScore")){
eng101scr.setText(data.getStringExtra("e101FinalScore"));
}
Eng101
public class Eng101 extends Activity {
Button btnSubmit;
EditText userGrade;
String strGrade;
OutsideVariables outside = new OutsideVariables();
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.eng101);
btnSubmit = (Button)findViewById(R.id.btnE101);
userGrade = (EditText)findViewById(R.id.eng101Scr);
btnSubmit.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
strGrade = userGrade.getText().toString();
Intent i = getIntent();
String msg = i.getStringExtra("grades");
if(msg.contentEquals("eng101")){
i.putExtra("e101FinalScore", strGrade);
setResult(RESULT_OK, i);
finish();
}
}
});
}
}