XML : How to save linearlayout state after OnClick

I'm trying to display a second layout after setVisibility(View.VISIBLE) in OnClick method (and add some checkboxes in the layout). This is working OK, the problem is when refreshing the activity, the view returns to the old state. I'm trying with sharedPreferences and onSaveInstanceState, but it's not working. I appreciate all the help. See the code below and this image

NoteEdit.class

      protected void onCreate(final Bundle savedInstanceState) {            super.onCreate(savedInstanceState);            mDbHelper = new NoteDbAdapter(this);          mDbHelper.open();              setContentView(R.layout.note_edit);          setTitle(R.string.edit_note);            addCheckButton = (Button) findViewById(R.id.add_check);            addCheckButton.setOnClickListener(new View.OnClickListener() {              @Override              public void onClick(View v) {              final LinearLayout ll = (LinearLayout) findViewById(R.id.linearLayout);                  ll.setVisibility(View.VISIBLE);               CheckBox cb = new CheckBox(findViewById(R.id.check).getContext());                      ll.addView(cb);                }      note_edit.xml    <?xml version="1.0" encoding="utf-8"?>  <ScrollView  xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="fill_parent"      android:layout_height="wrap_content">        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"          android:orientation="vertical" android:layout_width="match_parent"          android:layout_height="wrap_content"          android:id="@+id/linear" >            <LinearLayout              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:orientation="vertical"              android:id="@+id/linearLayout"              >              <CheckBox                  android:id="@+id/check"                  android:layout_width="wrap_content"                  android:layout_height="wrap_content"                  android:visibility="gone"                  />          </LinearLayout>            <EditText android:id="@+id/body" android:layout_width="match_parent"              android:hint="@string/body"              android:layout_height="400dp"              android:gravity="top"              android:scrollbars="vertical"              android:cursorVisible="true"/>            <Button android:id="@+id/add_check"              android:text="Add Checkbox"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:layout_alignParentBottom="true"              android:layout_alignParentLeft="true"              android:layout_alignParentStart="true" />      </LinearLayout>  </ScrollView>    

No comments:

Post a Comment