lundi 27 février 2017

NAVIGATION DRAWER: Saving a single checkbox state from the fragment

I am brand new to android programming and know this question has popped a lot, but no clear single answer to formulate a solution is given:

SAVING A CHECKBOX VALUE IN A FRAGMENT FROM A NAVIGATION DRAWER.

I only need to see the structure of the fragment to understand how to implement the save preferences , just a simple checkbox nothing else.

Kind Regards

MENU FRAGMENT:

public class Menu1 extends Fragment {

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup     container, @Nullable Bundle savedInstanceState) {
    //returning our layout file
    //change R.layout.yourlayoutfilename for each of your fragments
    return inflater.inflate(R.layout.fragment_menu_1, container, false);
}


@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    //you can set the title for your toolbar here for different fragments     different titles
    getActivity().setTitle("MODEL 1");
}

LAYOUT:

<RelativeLayout 
android:layout_width="match_parent"
android:layout_height="match_parent">

<CheckBox
    android:text="@string/checkbox"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="158dp"
    android:id="@+id/checkBox" />
</RelativeLayout>




Aucun commentaire:

Enregistrer un commentaire