Tôi không biết liệu bạn có coi đây là một cách dễ dàng hay không nhưng tôi đã thử những điều sau đây.
Xác định Xem bạn muốn trở lại trong xml riêng của mình (Tôi đã thử với một Button, chơi với visibilty, văn bản, ...)
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" />
Sau đó, trong chính bạn bố trí xác định một điểm chèn
<LinearLayout
android:id="@+id/buttonInsertLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
/>
Trong tải hoạt động của bạn View vào điểm chèn bằng cách sử dụng 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);
// ...
}
Sau đó trên phương thức đặt lại(), bạn có thể tăng cường phiên bản mới của chế độ xem, dựa trên nội dung xml và thay thế nội dung đã chỉnh sửa bằng nội dung mới.
public void resetView() {
ViewGroup parent = (ViewGroup)admin.getParent();
int index = parent.indexOfChild(admin);
parent.removeViewAt(index);
// Inflate a fresh new View corresponding to the initial state of the view
Button adminSave = (Button)View.inflate(UserLoggin.this, R.layout.button, null);
parent.addView(adminSave, index);
}
Hy vọng nó sẽ giúp ...
Câu hỏi của tôi là liệu có tồn tại một cách đơn giản để trở lại một Xem trạng thái XML ban đầu của nó, một cái gì đó như 'View.reset()'. Tôi không hỏi làm thế nào hoặc nơi tôi có thể thay đổi nó theo chương trình. – wvdz