Open top menu






Example- How to Implement Material Spinner in android?


Step 1 - For normal look use

compile 'com.weiwangcn.betterspinner:library:1.1.0'
 
If you have appcompat-v7 in your dependencies make sure to exclude it :

compile ('com.weiwangcn.betterspinner:library:1.1.0') {
    exclude
group: 'com.android.support', module: 'appcompat-v7'
}



Step 2- Add View main_activity.xml.



<com.weiwangcn.betterspinner.library.BetterSpinner
    android:id="@+id/spinner_sp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/edittext_view"
    android:hint="@string/select"
    android:padding="8dp"

     />
 
 
Step 3- Find View id in MainActivity.Java.

public class MainActivity extends AppCompatActivity {
 String[] age = {"12", "13","14","15","16","17","18","19","20",};

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        BetterSpinner Age_Sppiner = (BetterSpinner)
                                    findViewById(R.id.Age_Sppiner);

        ArrayAdapter arrayAdapterage = 
        new ArrayAdapter(listener, android.R.layout.
                                  simple_spinner_dropdown_item, age); 
                                
        Age_Sppiner.setAdapter(arrayAdapterage);
 

    }

}



0 comments