title: Unable to select item with button in custom spinner
body: <p>I am creating a custom spinner with button and textview in items of spinner.
  In this case, only the button's click is detected. And the click of complete item is not detected.
  But when I remove the button from the spinner item, the click of complete item works fine. Is it possible to handle both click events at a time? If yes, how we can implement it?</p>
  
  <p>The code is below:-</p>
  
  <pre><code>public class MainActivity extends Activity {
  
  String[] Languages = { "Select a Language", "C# Language", "HTML Language",
          "XML Language", "PHP Language" };
  // Declaring the Integer Array with resourse Id's of Images for the Spinners
  Integer[] images = { 0, R.drawable.image_1, R.drawable.image_2,
          R.drawable.image_3, R.drawable.image_4 };
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
      // Declaring and typecasting a Spinner
      final Spinner mySpinner = (Spinner) findViewById(R.id.spinner1);
  
      // Setting a Custom Adapter to the Spinner
      mySpinner.setAdapter(new MyAdapter(MainActivity.this, R.layout.custom,
              Languages));
  
  }
  
  // Creating an Adapter Class
  public class MyAdapter extends ArrayAdapter&lt;String&gt; {
  
      public MyAdapter(Context context, int textViewResourceId,
              String[] objects) {
          super(context, textViewResourceId, objects);
  
      }
  
      public View getCustomView(int position, View convertView,
              ViewGroup parent) {
  
          // Inflating the layout for the custom Spinner
          LayoutInflater inflater = getLayoutInflater();
          View layout = inflater.inflate(R.layout.custom, parent, false);
  
          // Declaring and Typecasting the textview in the inflated layout
          TextView tvLanguage = (TextView) layout
                  .findViewById(R.id.tvLanguage);
  
          // Setting the text using the array
          tvLanguage.setText(Languages[position]);
  
          // Setting the color of the text
          tvLanguage.setTextColor(Color.rgb(75, 180, 225));
  
          // Declaring and Typecasting the imageView in the inflated layout
          Button img = (Button) layout.findViewById(R.id.imgLanguage);
  
          // Setting an image using the id's in the array
          img.setOnClickListener(new OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // TODO Auto-generated method stub
                  Toast.makeText(getApplicationContext(),"Clicked",Toast.LENGTH_SHORT).show();
              }
          });
  
          int count = 0;
          // Setting Special atrributes for 1st element
          if (position == 0) {
              // Removing the image view
              img.setVisibility(View.GONE);
              // Setting the size of the text
              tvLanguage.setTextSize(20f);
              // Setting the text Color
              tvLanguage.setTextColor(Color.BLACK);
  
              count++;
              if(count ==0)
              tvLanguage.setVisibility(View.INVISIBLE);
          }
  
          return layout;
      }
  
      // It gets a View that displays in the drop down popup the data at the
      // specified position
      @Override
      public View getDropDownView(int position, View convertView,
              ViewGroup parent) {
  
          return getCustomView(position, convertView, parent);
      }
  
      // It gets a View that displays the data at the specified position
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
  
          return getCustomView(position, convertView, parent);
      }
  
  }
  
  public class CustomSpinnerSelection extends Spinner {
  
      private boolean mToggleFlag = true;
  
      public CustomSpinnerSelection(Context context, AttributeSet attrs,
              int defStyle, int mode) {
          super(context, attrs);
      }
  
      public CustomSpinnerSelection(Context context, AttributeSet attrs,
              int defStyle) {
          super(context, attrs, defStyle);
      }
  
      public CustomSpinnerSelection(Context context, AttributeSet attrs) {
          super(context, attrs);
      }
  
      public CustomSpinnerSelection(Context context, int mode) {
          super(context);
      }
  
      public CustomSpinnerSelection(Context context) {
          super(context);
      }
  
      @Override
      public int getSelectedItemPosition() {
          // this toggle is required because this method will get called in other
          // places too, the most important being called for the
          // OnItemSelectedListener
          if (!mToggleFlag) {
              return 0; // get us to the first element
          }
          return super.getSelectedItemPosition();
      }
  
      @Override
      public boolean performClick() {
          // this method shows the list of elements from which to select one.
          // we have to make the getSelectedItemPosition to return 0 so you can
          // fool the Spinner and let it think that the selected item is the first
          // element
          mToggleFlag = false;
          boolean result = super.performClick();
          mToggleFlag = true;
          return result;
      }
  
  }
  </code></pre>
  
  <p>}</p>