I’m creating a custom Dialog that is started by a custom spinner. What I was trying to do is customize the dialog the spinner calls. However, there is an annoying space in the dialog. I’ve tryied all my resources to fix it, but nothing. I also followed this question‘s answer but didn’t solve.
In the spinner xml file I pass it like this. It references the following class named CustomSpinner, that extends a Spinner:
<com.myproject.CustomSpinner
android:id="@+id/customSpinner"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="13dp"
android:prompt="@string/my_spinner"/>
And I have this class that is my custom dialog class:
public class CustomSpinnerDialog extends Dialog implements OnItemClickListener, View.OnClickListener
{
private OnItemSelectedListener onItemSelectedListener;
public DialogInterface.OnClickListener mListener;
public Context mContext;
public interface OnItemSelectedListener
{
public void onItemSelected(String itemValue);
}
public CustomSpinnerDialog(Context context, CustomSpinner.SpinnerAdapter spinnerAdapter, DialogInterface.OnClickListener listener)
{
super(context);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setContentView(R.layout.custom_spinner);
mListener = listener;
mContext = context;
ListView listView = (ListView) this.findViewById(R.id.listview);
listView.setAdapter(spinnerAdapter);
listView.setOnItemClickListener(this);
listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
public void setOnItemSelectedListener(OnItemSelectedListener listener)
{
this.onItemSelectedListener = listener;
}
@Override
public void onClick(View v)
{
if(mListener != null)
mListener.onClick(this, DialogInterface.BUTTON_POSITIVE);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
if(mListener != null)
mListener.onClick(this, position);
String text = (String) parent.getItemAtPosition(position);
onItemSelectedListener.onItemSelected(text);
}
public void setDialogTitle(String title)
{
TextView titleText = (TextView) this.findViewById(R.id.titleText);
titleText.setText(title);
}
}
And this is my custom spinner:
public class CustomSpinner extends Spinner implements DialogInterface.OnClickListener
{
public Context mContext;
public String[] mDataList;
public CustomSpinner(Context context, AttributeSet attrs)
{
super(context, attrs);
this.mContext = context;
}
@Override
public boolean performClick()
{
boolean handled = false;
if (!handled)
{
handled = true;
CustomSpinnerDialog dialog = new CustomSpinnerDialog(mContext, (ListAdapter) getAdapter(), this, R.style.FullHeightDialog);
dialog.setDialogTitle(mContext.getResources().getString((R.string.my_dialog_text)));
dialog.show();
}
return handled;
}
@Override
public void onClick(DialogInterface dialog, int which)
{
setSelection(which);
dialog.dismiss();
}
}
My Spinner is created like this in an Activity:
cSpinner= (CustomSpinner) findViewById(R.id.customSpinner);
cSpinner.setDataList(dataList);
cSpinner.setTag("CustomSpinner");
cSpinner.setOnItemSelectedListener(controller);
Here is a screenshot of how the dialog looks like:

I solved it following the documentation
And based in this code as advised by the documentation link above: