Created
September 28, 2015 12:44
-
-
Save burnix/d3defa1f5933158754c8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.support.v7.widget.RecyclerView; | |
import android.util.Log; | |
import android.view.LayoutInflater; | |
import android.view.View; | |
import android.view.ViewGroup; | |
import android.widget.AdapterView; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import com.squareup.picasso.Picasso; | |
import java.util.ArrayList; | |
import java.util.List; | |
/** | |
* Created by Igor on 06.09.2015. | |
*/ | |
public class GridAdapter extends RecyclerView.Adapter<GridAdapter.ViewHolder>{ | |
List<HeroItem> mItems; | |
Context mContext; | |
onItemClickListener listener; | |
ViewHolder holder; | |
public GridAdapter(Context context) { | |
super(); | |
this.mContext = context; | |
mItems = new ArrayList<HeroItem>(); | |
HeroItem species = new HeroItem(); | |
//species.setName("Amur Leopard"); | |
species.setThumbnail(R.drawable.test1); | |
mItems.add(species); | |
species = new HeroItem(); | |
//species.setName("Black Rhino"); | |
species.setThumbnail(R.drawable.test2); | |
mItems.add(species); | |
species = new HeroItem(); | |
//species.setName("Orangutan"); | |
species.setThumbnail(R.drawable.test3); | |
mItems.add(species); | |
species = new HeroItem(); | |
//species.setName("Sea Lions"); | |
species.setThumbnail(R.drawable.test4); | |
mItems.add(species); | |
species = new HeroItem(); | |
//species.setName("Indian Elephant"); | |
species.setThumbnail(R.drawable.test5); | |
mItems.add(species); | |
species = new HeroItem(); | |
// species.setName("Giant Panda"); | |
species.setThumbnail(R.drawable.test6); | |
mItems.add(species); | |
species = new HeroItem(); | |
//species.setName("Snow Leopard"); | |
species.setThumbnail(R.drawable.test1); | |
mItems.add(species); | |
species = new HeroItem(); | |
//species.setName("Dolphin"); | |
species.setThumbnail(R.drawable.test1); | |
mItems.add(species); | |
} | |
public void setListener(onItemClickListener onItemClick){ | |
listener = onItemClick; | |
} | |
@Override | |
public GridAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, final int i) { | |
View v = LayoutInflater.from(viewGroup.getContext()) | |
.inflate(R.layout.grid_item, viewGroup, false); | |
return new ViewHolder(v); | |
} | |
@Override | |
public void onBindViewHolder(ViewHolder viewHolder, final int position) { | |
HeroItem nature = mItems.get(position); | |
//viewHolder.tvspecies.setText(nature.getName()); | |
//viewHolder.imgThumbnail.setImageResource(nature.getThumbnail()); | |
Picasso.with(mContext) | |
.load(nature.getThumbnail()) | |
.into(viewHolder.imgThumbnail); | |
viewHolder.itemView. | |
} | |
@Override | |
public int getItemCount() { | |
return mItems.size(); | |
} | |
class ViewHolder extends RecyclerView.ViewHolder { | |
public ImageView imgThumbnail; | |
//public TextView tvspecies; | |
public ViewHolder(View itemView) { | |
super(itemView); | |
imgThumbnail = (ImageView) itemView.findViewById(R.id.photoView); | |
//tvspecies = (TextView)itemView.findViewById(R.id.tv_species); | |
} | |
} | |
interface onItemClickListener{ | |
void onClickListener(int position); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment