kaveer
1/22/2017 - 4:49 PM

Click button functionality in fragment

Click button functionality in fragment

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             xmlns:app="http://schemas.android.com/apk/res-auto"
             xmlns:tools="http://schemas.android.com/tools"
             android:layout_width="match_parent"
             android:layout_height="match_parent"
             tools:context="com.kavsoftware.kaveer.androidtutorials.Fragment.Widget.Button.ButtonFragment">

    <!-- TODO: Update blank fragment layout -->

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="@string/button"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"/>

        <Button
            android:id="@+id/buttonSourceCode"
            android:layout_width="368dp"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:text="@string/buttonSourceCode"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"/>
    </android.support.constraint.ConstraintLayout>

</FrameLayout>
Button buttonSave   = (Button)view.findViewById(R.id.BtnSaveTax);
        buttonSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(!GetVehicle()){
                    Toast messageBox = Toast.makeText(getActivity() , "No Vehicle!! add in vehicle section" , Toast.LENGTH_SHORT);
                    messageBox.show();
                    return;
                }
                if(IsValid()){
                    SetText();
                    InsertInsurance();

                    Toast messageBox = Toast.makeText(getActivity() , "New insurance added" , Toast.LENGTH_SHORT);
                    messageBox.show();
                }

            }
     });
Button buttonViewHistory   = (Button)view.findViewById(R.id.BtnViewTaxHistory);
        buttonViewHistory.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                InsuranceHistoryFragment fragment = new InsuranceHistoryFragment();
                android.support.v4.app.FragmentTransaction fmTransaction = getFragmentManager().beginTransaction();
                fmTransaction.replace(R.id.Frame_container, fragment);
                fmTransaction.commit();


            }


        });