Hi Pranav,
I updated the code based on your previous mail. Surely, it's only an
sample. You need make it more powerful & roubust.
2010/1/1 android09 <[email protected]>
> Hi Rui Wu,
>
> Happy New Year!!!!!
>
> Thanks for reply me with the code. I tried for the current activity
> which holds the data while the second activity is started and get back
> to the current activity by pressing the previous button with using of
> your code. But every time i got the NullPointerException error. I can
> go on next activity but when i trying to back on the previous
> activity, i got an exception.
>
> Here, i have placed my code without added your code and i want that
> you just modified this code and reply me. So, can you help me to out
> from this problem?
>
> The "first.xml" file consist two edittext and one button & the
> "second.xml" file consist one button. adds an edittext R.id.phonenumber
>
Person.java (in the same package for the code convenience; can access
member variables directly)
public class Person implements Serializable{
String fistName;
String lastName;
String phoneNumber;
}
>
> FirstActivity.java
> ------------------
>
> // Organised imports...
>
> public class FirstActivity extends Activity{
>
> private EditText edFirstName, edLastName;
> private Button btnNext;
>
> private Person mData;
> @Override
> public void onCreate(Bundle b){
> super.onCreate(b);
> setContentView(R.layout.first);
> Intent i = getIntent();
> mData = (Person)i.getSerializableExtra("DATA");
> if(mData == null) {
> mData = new Person();
> }
edFirstName = (EditText)findViewById(R.id.editFirst);
> edLastName = (EditText)findViewById(R.id.editLast);
> edFirstName.setText(mData.fistName);
> edLastName.setText(mData.lastName);
> btnNext = (Button)findViewById(R.id.btnNext);
> btnNext.setOnClickListener(new View.OnClickListener(){
>
> @Override
> public void onClick(View v){
> mData.fistName =
> edFirstName.getEditableText().toString();
> mData.lastName =
> edLastName.getEditableText().toString();
>
Intent intent = new
Intent(FirstActivity.this,
SecondActivity.class);
intent.putExtra("DATA", mData);
> startActivity(intent);
finish();
> }
> });
> }
> }
>
> SecondActivity.java
> -------------------
>
> // Organised imports...
>
> public class SecondActivity extends Activity{
>
> private Button btnPrev;
> private EditText mPhoneNumber;
> private Person mData;
> @Override
> public void onCreate(Bundle b){
> super.onCreate(b);
> setContentView(R.layout.second);
> mPhoneNumber = (EditText)findViewById(R.id.phonenumber);
> Intent i = getIntent();
> mData = (Person)i.getSerializableExtra("DATA");
> mPhoneNumber.setText(mData.phoneNumber);
> btnPrev = (Button)findViewById(R.id.btnPrevious);
> btnPrev.setOnClickListener(new View.OnClickListener(){
>
> @Override
> public void onClick(View v){
> mData.phoneNumber =
> mPhoneNumber.getEditableText().toString();
>
Intent intent = new
Intent(SecondActivity.this,
FirstActivity.class);
intent.putExtra("DATA", mData);
startActivity(intent);
finish();
}
});
}
}
Thanks,
> Regards,
> -------------
> Pranav
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to [email protected]
> To unsubscribe from this group, send email to
> [email protected]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>
--
BRs,
Rui
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en