Reputation: 631
I want to work with the spinner item. I want the drop down to have the same width and height than the button.
How can I do this?
Finally i solved it using a listview into a alertdialog like this:
public void seleccionaTemporada(View view) {
AlertDialog.Builder selector = new AlertDialog.Builder(SeleccionaTemporadaActivity.this);
selector.setTitle("Temporadas");
selector.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
selector.setAdapter(temporadas, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent(getApplicationContext(), DashBoardActivity.class);
intent.putExtra("temporada", temporadas.getItem(which));
startActivity(intent);
}
});
selector.show();
}
<Button
android:id="@+id/btn_selecciona_temporada"
android:layout_width="300dp"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginStart="70dp"
android:drawableStart="@mipmap/ic_balon"
android:onClick="seleccionaTemporada"
android:text="@string/seleccionarTemporada"
android:textSize="25sp" />
For my needs it is the best solution i think. Sorry for my bad explanation before.
Upvotes: 0
Views: 258
Reputation: 36
You can use Popup Window. And create your own Spinner Popup. Example Code below
LayoutInflater inflater = (LayoutInflater)parentActivity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.pop_up_window, null);
RelativeLayout layout1 = holder.relativeLayout_multiChoiceDropDown;
pw = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
pw.setBackgroundDrawable(new BitmapDrawable());
pw.setTouchable(true);
pw.setOutsideTouchable(true);
pw.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
pw.setTouchInterceptor(new View.OnTouchListener()
{
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_OUTSIDE)
{
pw.dismiss();
return true;
}
return false;
}
});
pw.setContentView(layout);
pw.showAsDropDown(layout1, -5, 0);
final ListView list = (ListView) layout.findViewById(R.id.dropDownList);
Adapter_DropDown adapter = new Adapter_DropDown(parentActivity, items);
list.setAdapter(adapter);
pop_up_window.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="@+id/PopUpView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/qatool_basic_info_dropdown"
android:orientation="vertical">
<ListView
android:id="@+id/dropDownList"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:divider="#000"
android:dividerHeight="0.5dp">
</ListView>
</LinearLayout>
Upvotes: 1