Custom Spinner Adapter

后端 未结 5 1164
借酒劲吻你
借酒劲吻你 2020-11-30 07:19

I wanted to apply a custom font to my spinner. The only way i found out is that to create a custom adapter. Here is my code

    private class CustomAdapter e         


        
5条回答
  •  生来不讨喜
    2020-11-30 07:44

    The simplest, I think :)

    List listOfItems = getListOfItems(); // returns ArrayList
    
    ArrayAdapter spinnerAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, listOfItems);
    
    targetSpinner.setAdapter(spinnerAdapter);
    

    Ok, to simply put a list of string in a spinner shouldn't force us to implement an Adapter. That's a code blot and getting a bit pattern crazy, I think.

    Trick is the simple_spinner_item id - damn, I like the R.id mechanism but this isn't intuitive from the docs.

提交回复
热议问题