I am creating a custom dialog that is triggered by a custom counter. What I was trying to do was set up the dialog that the spinner calls. However, the dialog box has annoying space. I tried all my resources to fix this, but nothing. I also fulfilled this question answer, but did not solve it.
In the spinner xml file, I pass it like this. It refers to the following class called CustomSpinner, which extends 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, which is my special 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 own counter:
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 as follows:
cSpinner= (CustomSpinner) findViewById(R.id.customSpinner); cSpinner.setDataList(dataList); cSpinner.setTag("CustomSpinner"); cSpinner.setOnItemSelectedListener(controller);
Here is a screenshot of what the dialog looks like:
