Q: Switch case with radio buttons I am new to here and java. I am developing an android app with radio buttons which calculates the SGPA of a student. Every subject has it's own credits which gets multiplies by the respective grade and after the addition of all products of the subject, The sum is divided by the total credits... 
So far i've completed the xml code properly but i am stuck in the java main activity... I just need an example of only one button or subject and rest i will do on my own... I want to use switch case to first check which radio button is clicked and then do the respective calculations.
XML CODE
<TextView
        android:id="@+id/maths"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#F44336"
        android:text="MATHEMATICS"
        android:textAlignment="center"
        android:textAllCaps="true"
        android:textAppearance="?android:textAppearanceLarge"
        android:textStyle="bold" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#F44336"
        android:orientation="horizontal">

        <RadioGroup
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="7"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/Omaths"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="O"
                android:onClick="onRadioButtonClicked"/>

            <RadioButton
                android:id="@+id/Aplusmaths"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="A+"
                android:onClick="onRadioButtonClicked"/>

            <RadioButton
                android:id="@+id/Amaths"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="A"
                android:onClick="onRadioButtonClicked"/>

            <RadioButton
                android:id="@+id/Bplusmaths"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="B+"
                android:onClick="onRadioButtonClicked"/>

            <RadioButton
                android:id="@+id/Bmaths"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="B"
                android:onClick="onRadioButtonClicked"/>

            <RadioButton
                android:id="@+id/Cmaths"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="C"
                android:onClick="onRadioButtonClicked"/>

            <RadioButton
                android:id="@+id/Pmaths"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="P"
                android:onClick="onRadioButtonClicked"/>
        </RadioGroup>
    </LinearLayout>

AND THE JAVA MAIN ACTIVITY CODE IS
package droidmentor.bnv_with_viewpager;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.RadioButton;
import android.widget.TextView;

import droidmentor.bnv_with_viewpager.Fragment.CallsFragment;
import droidmentor.bnv_with_viewpager.Fragment.ChatFragment;
import droidmentor.bnv_with_viewpager.Fragment.ContactsFragment;
import static droidmentor.bnv_with_viewpager.R.id.Amaths;
import static droidmentor.bnv_with_viewpager.R.id.Bmaths;
import static droidmentor.bnv_with_viewpager.R.id.Bplusmaths;
import static droidmentor.bnv_with_viewpager.R.id.Cmaths;
import static droidmentor.bnv_with_viewpager.R.id.Pmaths;

public class MainActivity extends AppCompatActivity {


    BottomNavigationView bottomNavigationView;

    //This is our viewPager
    private ViewPager viewPager;


    //Fragments

    ChatFragment chatFragment;
    CallsFragment callsFragment;
    ContactsFragment contactsFragment;
    MenuItem prevMenuItem;

    //Instance Variables For Each Subject

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_main);
        //Initializing viewPager
        viewPager = (ViewPager) findViewById(R.id.viewpager);

        //Initializing the bottomNavigationView
        bottomNavigationView = (BottomNavigationView)findViewById(R.id.bottom_navigation);

        bottomNavigationView.setOnNavigationItemSelectedListener(
                new BottomNavigationView.OnNavigationItemSelectedListener() {
                    @Override
                    public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                        switch (item.getItemId()) {
                            case R.id.action_call:
                                viewPager.setCurrentItem(0);
                                break;
                            case R.id.action_chat:
                                viewPager.setCurrentItem(1);
                                break;
                            case R.id.action_contact:
                                viewPager.setCurrentItem(2);
                                break;
                        }
                        return false;
                    }
                });

        viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                if (prevMenuItem != null) {
                    prevMenuItem.setChecked(false);
                }
                else
                {
                    bottomNavigationView.getMenu().getItem(0).setChecked(false);
                }
                Log.d("page", "onPageSelected: "+position);
                bottomNavigationView.getMenu().getItem(position).setChecked(true);
                prevMenuItem = bottomNavigationView.getMenu().getItem(position);

            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

       /*  //Disable ViewPager Swipe

       viewPager.setOnTouchListener(new View.OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                return true;
            }
        });

        */

        setupViewPager(viewPager);
    }
    //This method is called when button is pressed
    public void calculate(View view) {
        display(9);
    }

    //This method returns the SGPA
    private void display(int number) {
        TextView sgpa = (TextView) findViewById(R.id.sgpa);
        sgpa.setText("" + number);
    }

    private void setupViewPager(ViewPager viewPager) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
        callsFragment=new CallsFragment();
        chatFragment=new ChatFragment();
        contactsFragment=new ContactsFragment();
        adapter.addFragment(callsFragment);
        adapter.addFragment(chatFragment);
        adapter.addFragment(contactsFragment);
        viewPager.setAdapter(adapter);
    }
}

I know i can use the user input method with edit text but i have to use radio buttons... :)

A: try do this to get selected button:
int radioButtonID = radioButtonGroup.getCheckedRadioButtonId();
View radioButton = radioButtonGroup.findViewById(radioButtonID);
int idx = radioButtonGroup.indexOfChild(radioButton);

Note that if you use textview or other view inside radioGroup not equal to radiobutton you get wrong index.
To get the text of selected button:
RadioButton r = (RadioButton)  radioButtonGroup.getChildAt(idx);
String selectedtext = r.getText().toString();

