Android Open Source - checkin Icon Spinner Adapter






From Project

Back to project page checkin.

License

The source code is released under:

# License Copyright ? 2014 Sam Whited Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ?Software??), to deal ...

If you think the Android project checkin listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.samwhited.checkin;
/*from  w  ww.  j a  va 2s  . c  o  m*/
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.SpinnerAdapter;
import android.widget.TextView;

public class IconSpinnerAdapter extends ArrayAdapter implements SpinnerAdapter {

  final String[] icons;

  /**
   * Constructor
   *
   * @param context  The current context.
   * @param resource The resource ID for a layout file containing a TextView to use when
   *                 instantiating views.
   * @param names    The objects to represent in the ListView.
   * @param icons    The icons to show next to the names in the ListView.
   */
  public IconSpinnerAdapter(final Context context,
                final int resource,
                final String[] names,
                final String[] icons) {
    super(context, resource, names);
    this.icons = icons;
  }

  /**
   * {@inheritDoc}
   *
   * @param position
   * @param convertView
   * @param parent
   */
  @Override
  public View getView(final int position, final View convertView, final ViewGroup parent) {
    final View view = super.getView(position, convertView, parent);
    if (view != null && view instanceof TextView) {
      if (!icons[position].isEmpty() && !icons[position].equalsIgnoreCase("none")) {
        ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(
            getContext().getResources().getIdentifier(icons[position].replace("-", "_"),
                "drawable",
                getContext().getPackageName()), 0, 0, 0);
      } else {
        ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
      }
    }
    return view;
  }

  /**
   * {@inheritDoc}
   *
   * @param position
   * @param convertView
   * @param parent
   */
  @Override
  public View getDropDownView(final int position, final View convertView, final ViewGroup parent) {
    final View view = super.getDropDownView(position, convertView, parent);
    if (view != null && view instanceof TextView) {
      if (!icons[position].isEmpty() && !icons[position].equalsIgnoreCase("none")) {
        ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(
            getContext().getResources().getIdentifier(icons[position].replace("-", "_"),
                "drawable",
                getContext().getPackageName()), 0, 0, 0);
      } else {
        ((TextView) view).setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
      }
    }
    return view;
  }
}




Java Source Code List

com.samwhited.checkin.CheckInActivity.java
com.samwhited.checkin.CheckInDB.java
com.samwhited.checkin.CheckInFragment.java
com.samwhited.checkin.CheckInHandler.java
com.samwhited.checkin.CheckInListAdapter.java
com.samwhited.checkin.CheckInListFragment.java
com.samwhited.checkin.CheckInListItem.java
com.samwhited.checkin.CheckInListLoader.java
com.samwhited.checkin.CheckInList.java
com.samwhited.checkin.CheckInOpenHelper.java
com.samwhited.checkin.IconSpinnerAdapter.java
com.samwhited.checkin.SettingsActivity.java
com.samwhited.checkin.SettingsFragment.java
com.samwhited.checkin.database.CheckInDB.java
com.samwhited.checkin.database.CheckInOpenHelper.java
com.samwhited.checkin.model.CheckIn.java
com.samwhited.checkin.util.CheckInPreferences.java
com.samwhited.checkin.util.Formatting.java
com.samwhited.checkin.util.GeoJSON.java
com.samwhited.checkin.util.NetworkUtils.java