The Android Developer Challenge is back! Submit your idea before December 2.

Helper

class Helper
kotlin.Any
   ↳ androidx.appcompat.widget.ThemedSpinnerAdapter.Helper

A helper class which allows easy integration of ThemedSpinnerAdapter into existing SpinnerAdapters in a backwards compatible way.

An example BaseAdapter implementation would be:

public class MyAdapter extends BaseAdapter implements ThemedSpinnerAdapter {
          private final ThemedSpinnerAdapter.Helper mDropDownHelper;
     
          public CheeseAdapter(Context context) {
              mDropDownHelper = new ThemedSpinnerAdapter.Helper(context);
              // ...
          }
     
          @Override
          public View getDropDownView(int position, View convertView, ViewGroup parent) {
              View view;
     
              if (convertView == null) {
                  // Inflate the drop down using the helper's LayoutInflater
                  LayoutInflater inflater = mDropDownHelper.getDropDownViewInflater();
                  view = inflater.inflate(R.layout.my_dropdown, parent, false);
              }
     
              // ...
          }
     
          @Override
          public void setDropDownViewTheme(@Nullable Resources.Theme theme) {
              // Pass the new theme to the helper
              mDropDownHelper.setDropDownViewTheme(theme);
          }
     
          @Override
          public Resources.Theme getDropDownViewTheme() {
              // Return the helper's value
              return mDropDownHelper.getDropDownViewTheme();
          }
      }
      

Summary

Public constructors

<init>(@NonNull context: Context)

Public methods

LayoutInflater

Returns the LayoutInflater which should be used when inflating any layouts from your SpinnerAdapter#getDropDownView(int, View, ViewGroup).

Theme?

Should be called from your adapter's ThemedSpinnerAdapter#getDropDownViewTheme(), returning the value returned from this method.

Unit
setDropDownViewTheme(@Nullable theme: Theme?)

Should be called from your adapter's ThemedSpinnerAdapter#setDropDownViewTheme(Theme)

Public constructors

<init>

Helper(@NonNull context: Context)

Public methods

getDropDownViewInflater

@NonNull fun getDropDownViewInflater(): LayoutInflater

Returns the LayoutInflater which should be used when inflating any layouts from your SpinnerAdapter#getDropDownView(int, View, ViewGroup).

The instance returned will have a correct theme, meaning that any inflated views will be created with the same theme.

getDropDownViewTheme

@Nullable fun getDropDownViewTheme(): Theme?

Should be called from your adapter's ThemedSpinnerAdapter#getDropDownViewTheme(), returning the value returned from this method.

setDropDownViewTheme

fun setDropDownViewTheme(@Nullable theme: Theme?): Unit

Should be called from your adapter's ThemedSpinnerAdapter#setDropDownViewTheme(Theme)

Parameters
theme Theme?: the theme passed in to ThemedSpinnerAdapter#setDropDownViewTheme(Theme)