Headertab

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Saturday, 12 March 2016

Spinner

Hello guys if you want custom spinner and multi selection spinner then download this sample and enjoy it.

simplefragment.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >


    <TextView
        android:id="@+id/txt"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Simple Spinner" />


    <Spinner
        android:layout_below="@+id/txt"
        android:id="@+id/simple_spinner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:dropDownVerticalOffset="40dp"
        android:spinnerMode="dropdown"
        android:drawSelectorOnTop="false"


        />



</RelativeLayout>

SimpleFragment.java

public class SimpleSpinnerFragment extends Fragment {


    String[] values = new String[]{
            "Android Cupcake",
            "Android Donut",
            "Android Ecleir",
            "Android Frayo",
            "Android Gingerbread",
            "Android Honycomb",
            "Android Icecreame",
            "Android Jellybean",
            "Android Kitkat",
            "Android Lollypop",
            "Android Marsmolo"
    };
    View view;
    Spinner spinner;
    RelativeLayout layout;
    public SimpleSpinnerFragment() {
        // Required empty public constructor
    }




    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                            Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_simple_spinner, container, false);
        spinner = (Spinner) view.findViewById(R.id.simple_spinner);
        layout=(RelativeLayout)view.findViewById(R.id.parent);
        setSpinner();
        return view;
    }


    private void setSpinner() {
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, values);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spinner.setAdapter(dataAdapter);


        //set OnItemselected listener
        spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                Snackbar snackbar = Snackbar.make(layout, "You click "+values[position], Snackbar.LENGTH_LONG);


                snackbar.show();
            }


            @Override
            public void onNothingSelected(AdapterView<?> parent) {


            }
        });
    }



}


Thank you

Source code

https://github.com/SamsetDev/Spinner