Stack Exchange
Android custom spinner taking entire height

public class CustomSpinnerAdapter extends BaseAdapter{
private Context context;
private ArrayList<String> arr;


public CustomSpinnerAdapter(Context context, int textViewResourceId,
        ArrayList<String> objects) {

    // TODO Auto-generated constructor stub
    this.context = context;
    arr = objects;
}

@Override
public View getDropDownView(int position, View convertView,
        ViewGroup parent) {
    // TODO Auto-generated method stub
    return getCustomView(position, convertView, parent);
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    return getCustomView(position, convertView, parent);
}

public View getCustomView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    //return super.getView(position, convertView, parent);

    LayoutInflater mInflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View row=mInflater.inflate(R.layout.spinner_item, parent, false);

    TextView accountNumber = (TextView) row
            .findViewById(R.id.accountNumber);
    TextView accountType = (TextView) row
            .findViewById(R.id.accountType);
    TextView balance = (TextView) row
            .findViewById(R.id.balance);
    accountNumber.setText("accountType");
    balance.setText("balance");
    accountType.setText("accountNumber");
    return row;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return arr.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return  arr.get(position);
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

}
When I call this class, I am getting the spinner taking very very long height...
spinner_item

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
 android:orientation="vertical"
android:layout_height="wrap_content" >
<TextView
    android:id="@+id/accountNumber"
    style="@style/listViewPrimaryDetail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ellipsize="marquee"
    android:singleLine="true"
    android:paddingLeft="10dp"
    android:paddingTop="10dp" />
<TextView
    android:id="@+id/accountType"
    style="@style/listViewSecondaryDetail"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@id/accountNumber"
    android:ellipsize="marquee"
    android:paddingBottom="10dp"
    android:paddingLeft="10dp" />
<TextView
    android:id="@+id/balance"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_centerInParent="true"
    android:layout_alignParentRight="true"
    android:ellipsize="marquee" />
   </RelativeLayout>


So what happens? whats wrong?

         Spinner spinner = (Spinner) rootView
                    .findViewById(R.id.planets_spinnerqw);
            CustomSpinnerAdapter adapter = new CustomSpinnerAdapter(
                    container.getContext(),R.layout.spinner_item, values);
            // Apply the adapter to the spinner
            spinner.setAdapter(adapter);


So why does this code not work? in activity i read the spinner..allocate to it the custom adapter.. in custom adapter i specified layout spinner_item.. its taking entire height and not design i want.
if i specify the relative layout in spinner_item say instead of wrap_content layout_height="100dp" it works better... why this happening?

android:layout_height="match_parent" on your last textview. Should be android:layout_height="wrap_content"

CustomSpinnerAdapter what is use of arr and where you use it ?

No use for it now, just trying to get design first. i will fill values later. what pedro said worked perfectly, but i like to know why ? i mean match_parent for relative layout which is height wrap content..why i needed to switch to wrap content?

wrapping a layout on an element with a match_parent size is not defining anything. Basically, you say the container has to reduce its size to the size taken by its content, and you're asking the content to take as much space as allowed by the container => which result in both taking the maximum space possible

I have the same design but not inside custom spinner, and it works fine by giving layout_height as match parent in the textview..
