Skip to content

Instantly share code, notes, and snippets.

@chakrit
Created March 4, 2015 14:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chakrit/8c95a387464ee026f6b4 to your computer and use it in GitHub Desktop.
Save chakrit/8c95a387464ee026f6b4 to your computer and use it in GitHub Desktop.
package com.example.adapters;
import android.graphics.drawable.ColorDrawable;
import android.view.View;
import android.view.ViewGroup;
import com.example.R;
import com.example.models.Brand;
import com.example.models.ImageKind;
import javax.inject.Inject;
public class BrandsAdapter extends RootAdapter {
public interface OnPinClickListener {
void onPinClick(Brand brand);
}
private OnPinClickListener _onPinClickListener = null;
@Inject BrandsAdapter() { }
public void setOnPinClickListener(OnPinClickListener listener) {
_onPinClickListener = listener;
}
@Override public int getCount() { return root.brands.size(); }
@Override public Object getItem(int i) { return root.brands.get(i); }
@Override public View getView(int i, View view, ViewGroup container) {
if (view == null) {
view = inflater.inflate(R.layout.row_brand, container, false);
}
final Brand brand = (Brand) getItem(i);
ColorDrawable bgColor = new ColorDrawable(brand.color | 0xFF000000);
views.setImage(view, R.id.img_brand_logo, brand, ImageKind.LOGO_ON_DARK);
views.find(view, R.id.container_backdrop).setBackground(bgColor);
View.OnClickListener listener = new View.OnClickListener() {
@Override public void onClick(View view) {
if (_onPinClickListener != null) {
_onPinClickListener.onPinClick(brand);
}
}
};
views.setOnClickListener(view, listener, R.id.img_location_pin);
return view;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment