Q:

Selected spinner and a button click

I have 2 Spinner(Dropdown list) and a Button inside fragment
spinner1 is for Subject(ex SpinnerItem: Math, Science, English)
spinner2 is for Quarter(ex SpinnerItem: Quarter 1,Quarter 2,Quarter 3,Quarter 4)
When user select value from spinner1 and spinner2 and and they click the button they should move to a new fragment with a list of names depends on what they selected from the spinners
onCreateView
public Fragment() {

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {

    View view = inflater.inflate(R.layout.fragment_layout, container,
            false);

    // SPINNER1
    Spinner spinner1 = (Spinner) view.findViewById(R.id.spinSubject);
    Spinner spinner2 = (Spinner) view.findViewById(R.id.spinQuarter);
    spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
                //what to do
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
                //what to do

        }
    });

    // BUTTON
    Button btnSearch = (Button) view.findViewById(R.id.btnSearch);
    btnSearch.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.btnSearch:
               FragmentManager fm = getFragmentManager();
               FragmentTransaction ft = fm.beginTransaction();
               ft.replace(R.id.content_frame, new SubjectandQuarter());
                ft.commit();
             break;
            }
        }   
    });   

    return view;
}

XML TextView
<TextView
    android:id="@+id/tvSubject"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/subject_here"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<TextView
    android:id="@+id/tvQuarter"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/quarter_here"
    android:textAppearance="?android:attr/textAppearanceLarge" />

SubjectandQuarter class
public class SubjectandQuarterextends Fragment {

public SubjectandQuarter() {

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

      View view = inflater.inflate(R.layout.subjectandquarter, container,
                  false);

      TextView tvSubject = (TextView) view.findViewById(R.id.tvSubject);
      TextView tvQuarter = (TextView) view.findViewById(R.id.tvQuarter);

      return view;
}

}
I don't know if I'm doing it right. Hope someone can help me with my problem(new in android)
The output should be like(ListView):

A:

Try this..
Use spinner1.getSelectedItem().toString().trim(); in your code
btnSearch.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
        case R.id.btnSearch:

           String spi1 = spinner1.getSelectedItem().toString().trim();  
           String spi2 = spinner2.getSelectedItem().toString().trim();              

           Toast.makeText(getActivity(), "Spinner1 = "+spi1+" Spinner2 = "+spi2, Toast.LENGTH_LONG).show();

           FragmentManager fm = getFragmentManager();
           FragmentTransaction ft = fm.beginTransaction();
           SubjectandQuarter fragment = new SubjectandQuarter();
           Bundle bundle = new Bundle();
           bundle.putString("spinner1", spi1);
           bundle.putString("spinner2", spi2);
           fragment.setArguments(bundle); 
           ft.replace(R.id.content_frame, fragment);
            ft.commit();
         break;
        }
    }   
}); 

and 
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

      View view = inflater.inflate(R.layout.subjectandquarter, container,
                  false);

      String spi1,spi2;
      Bundle args = getArguments();
      if (args  != null && args.containsKey("spinner1"))
           spi1 = args.getString("spinner1");

      if (args  != null && args.containsKey("spinner2"))
           spi2 = args.getString("spinner2");

      TextView tvSubject = (TextView) view.findViewById(R.id.tvSubject);
      TextView tvQuarter = (TextView) view.findViewById(R.id.tvQuarter);

      tvSubject.setText(spi1); 
      tvQuarter.setText(spi2);

      return view;
}

