No one having an idea on how to implement it with a peice of code?
On Feb 2, 10:36 pm, Odessa Silverberg
<[email protected]> wrote:
> Hi,
>
> i'm having a problem. I got a CustomView (extend AutoCompleteTextView)
> which stores a certain value (additionall to the one whichis visible
> in the TextView part), but when i open another activity (to edit a
> certain record) and then return to my activity with the CustomView,
> the value it stored isn't saved.
>
> I know that the objects/UI is recreated when another activity gets
> focus or when you change perspective. Well now i'm trying to implement
> a feature which will preserve the values inside my CustomView. I've
> come so far that i know that i need to override onSaveInstanceState()
> and onRestoreInstanceState().
>
> But i'm not actually sure of who exactly make the implementation and
> how to work with Parcel and Parcelable Interfaces.
>
> So i'd need a simple example which will make sure that the TextView as
> well as my variable is preserved when the screen flips or another
> application gets focus. I couldn't find anything in the internet, only
> examples on how to implement onSaveInstanceState() and
> onRestoreInstanceState() for an Activity. The Activity uses Bundle
> class, which is easy to use and you can save values with state.put
> ("MYVALUE", myvalue);
>
> However, i cant use bundle with classes which extends View class
> (TextView, AutoCompleteTextView etc), as it will give me a casting
> error if i try to convert the TextViews state into a bundle like in
> the code below
>
> @Override
> public Parcelable onSaveInstanceState() {
> Bundle b = null;
> Parcelable p = super.onSaveInstanceState();
>
> // We have no state, return null
> if(p==null)
> return null;
>
> try{
> b = new Bundle((Bundle)p);
> if(contactId>0)
> b.putLong(CONTACT_ID, contactId);
> } catch(Exception ex){
> Log.e(LOG_TAG,ex.getMessage(), ex);
> }
>
> return b;
> }
>
> Can anyone post a piece of code as example on how to do it?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---