Bassicly my aim is too extend a activity so when the user presses Next how many times he wants to , i want to be able to display the value in the Activity2.
I want to somehow still keep the values stored into the variables even when i go into a new activity – im not too sure if thats possible. Any help would be appreciated
1st class
public class Activity extends Activity1 implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.Next:
if (value==0) {
value=1;
}
else if(value==1){
value=2
break;
}
case R.id.one:
Intent i1 = new Intent(this, Form.class);
startActivity(i1);
}
}
}
2nd Class
public class Activityv2 extends Activity1 implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()){
case R.id.button:
if(value==1){
display.setText("1");
}
else if(value==2)
{
display.setText("2");
}
}
}
}
you can store the value in a public static field.
Edit: or you can save it in SharedPreferences, or pass this value through the activity using the bundle
For instance you can save it in this way: