Reputation: 430
I have a form and there is two page to it. Therefore on the top right hand corner, there are two buttons, named "Page 1" and "Page 2" respectively.
The issue now is that how do I make it possible to alternate between the two pages without the data entered being erased. For example, probably I fill in name and address in Page 1, then I select Page 2 and enter some details in it before returning to Page 1 and the name and address should still remain there. How can I do it?
*Lastly, I would need to save it (both Page 1 and 2), how do I save without the application crashing on me? (Meaning being in Page 1 would still allow me to save whatever that's in Page 2).
Thanks for the time, I would be more than glad to elaborate if there's any doubts on my question.
Something of what I've done, but not quite successful:
public class EditForm extends Activity {
Button page1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.prepostform);
page1 = (Button)findViewById(R.id.btnPage1);
Button page2 = (Button)findViewById(R.id.btnPage2);
//do nth to page 1 button, dim the button
page1.setAlpha((float) 0.5);
//if page 2 selected, switch view to page2, disable btnPage1
page2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.prepostform2);
Button pg1 = (Button)findViewById(R.id.btnPg1);
Button pg2 = (Button)findViewById(R.id.btnPg2);
pg2.setAlpha((float) 0.5);
pg1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
setContentView(R.layout.prepostform);
page1.setAlpha((float) 0.5);
}
});
}
});
}
}
Upvotes: 0
Views: 733
Reputation: 430
In the end I found ViewFlipper. It's great, just exactly what I need. Buttons to change the page but able to retain the data =) thanks everyone too!
Found the tutorial sample here : http://meerlight.com/2011/03/simple-viewflipper-example/
Upvotes: 0
Reputation: 1201
In looking over your code, it seems like you should definitely use a TabHost. It's probably not wise to disregard this particular layout.
I'd check out this. That being said, you can then save the text from the input in the onPause() method of each activity.
Upvotes: 0
Reputation: 2528
From your main page, for the first time pass some null values to both the pages.
After that, while returning from the opened page, return the values which you typed there. And save that values in your main page.
For each opening the page1 or page2 pass the result in the main page to that opened pages.
Upvotes: 1