title: add and remove spinner dynamically
body: <p>Hi I have created a layout which contains two buttons add and remove, when i click on the plus button it will add a spinner pro-grammatically and i have another button (remove) with - sign as you can see in the picture , now i want when i click to the remove button it will delete the spinner from last, please guide me how can i delete the spinner? i have add the spinner pro-grammatically and it is creating spinner pro-grammatically. i'll post my code.
  <img src="https://i.stack.imgur.com/PR6Qb.png" alt="enter image description here">  </p>
  
  <pre><code>public class AddMenulist extends Fragment{
  
      TextView tv1,tv2,tv3,tv4;
      Button bt1 , bt2;
      LinearLayout linearlayout,linearlayout1;
  
      ArrayList&lt;String&gt; spinnerArray = new ArrayList&lt;String&gt;();
       private Spinner spinner;
       private Spinner spinner2;
  
      public AddMenulist(){
  
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.fragment_pages, container, false);
  
          tv1 = (TextView)rootView.findViewById(R.id.userName);
          tv2 = (TextView)rootView.findViewById(R.id.userName2);
  
          bt1 = (Button)rootView.findViewById(R.id.add);
          bt2 = (Button)rootView.findViewById(R.id.delete);
  
          linearlayout = (LinearLayout)rootView.findViewById(R.id.main_layout);
  
          spinnerArray.add("one");
          spinnerArray.add("two");
          spinnerArray.add("three");
          spinnerArray.add("four");
          spinnerArray.add("five");
  
         bt1.setOnClickListener(new View.OnClickListener()
         {
  
  
  
  
              @Override
              public void onClick(View view)
              {
  
                  //Toast.makeText(getActivity(), "Test", Toast.LENGTH_LONG).show();
  
                  linearlayout1 = new LinearLayout(getActivity());
                  LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                  linearlayout1.setOrientation(LinearLayout.HORIZONTAL);
                  layoutParams.setMargins(10, 0, 0, 0);
                  linearlayout1.setLayoutParams(layoutParams );
  
  
                  tv3 = new TextView(getActivity());
                  tv3.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL);
                  tv3.setText("Label");
  
                  tv4 = new TextView(getActivity());
                  tv4.setText("Category");
  
  
  
  
                  spinner = new Spinner(getActivity());
                  ArrayAdapter&lt;String&gt; spinnerArrayAdapter = new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_spinner_dropdown_item, spinnerArray);
  
                  spinner.setAdapter(spinnerArrayAdapter);
  
                  spinner2 = new Spinner(getActivity());
                  ArrayAdapter&lt;String&gt; spinnerArrayAdapter2 = new ArrayAdapter&lt;String&gt;(getActivity(), android.R.layout.simple_spinner_dropdown_item, spinnerArray);
  
                  spinner2.setAdapter(spinnerArrayAdapter2);
  
                  linearlayout1.addView(tv3);
                  linearlayout1.addView(spinner);
  
                  linearlayout1.addView(tv4);
                  linearlayout1.addView(spinner2);
                  linearlayout.addView(linearlayout1);
  
  
              }
          });
  
         bt2.setOnClickListener(new View.OnClickListener()
         {
              @Override
              public void onClick(View view)
              {
  
                  //Toast.makeText(getActivity(), "Test", Toast.LENGTH_LONG).show();
  
  
              }
          });
  
  
          return rootView;
      }
  
  
  }
  </code></pre>