android - Restore View to original xml state -



android - Restore View to original xml state -

in android, there easy way restore view state defined in xml?

for example, have view in xml:

<edittext android:id="@+id/set_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:inputtype="text" android:ems="10" android:visibility="gone" > </edittext>

now programmatically, visibility set visible, user enters text it, error gets set .seterror, , want revert view it's original state, without having explicitly do:

view.setvisibility(view.gone); view.settext(""); view.seterror(null);

i don't if consider easy way tried following.

define view want revert in own xml ( tried button, playing visibilty, text, ... )

button.xml

<?xml version="1.0" encoding="utf-8"?> <button xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/adminuser2" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginleft="20dp" android:layout_marginright="20dp" android:layout_margintop="10dp" android:text="@string/admin_user" />

then in main layout define insertion point

<linearlayout android:id="@+id/buttoninsertlayout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="10dp" />

in activity load view insertion point using inflater

private button admin; @override protected void onresume() { super.onresume(); admin = (button)view.inflate(userloggin.this, r.layout.button, null); viewgroup insert = (viewgroup)findviewbyid(r.id.buttoninsertlayout); insert.addview(admin); // ... }

later on reset() method can inflate new instance of view, based on xml content, , replace modified 1 new one.

public void resetview() { viewgroup parent = (viewgroup)admin.getparent(); int index = parent.indexofchild(admin); parent.removeviewat(index); // inflate fresh new view corresponding initial state of view button adminsave = (button)view.inflate(userloggin.this, r.layout.button, null); parent.addview(adminsave, index); }

hope helps...

android view

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -