use of com.mikepenz.fastadapter.app.items.ImageItem in project FastAdapter by mikepenz.
the class ImageListActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.sample_image_list);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter which will manage everything
mFastItemAdapter = new FastItemAdapter<>();
//init the ClickListenerHelper which simplifies custom click listeners on views of the Adapter
mClickListenerHelper = new ClickListenerHelper<>(mFastItemAdapter);
//configure our fastAdapter
mFastItemAdapter.withOnClickListener(new FastAdapter.OnClickListener<ImageItem>() {
@Override
public boolean onClick(View v, IAdapter<ImageItem> adapter, ImageItem item, int position) {
Toast.makeText(v.getContext(), item.mName, Toast.LENGTH_SHORT).show();
return false;
}
});
//get our recyclerView and do basic setup
RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
//find out how many columns we display
int columns = getResources().getInteger(R.integer.wall_splash_columns);
if (columns == 1) {
//linearLayoutManager for one column
rv.setLayoutManager(new LinearLayoutManager(this));
} else {
//gridLayoutManager for more than one column ;)
rv.setLayoutManager(new GridLayoutManager(this, columns));
}
rv.setItemAnimator(new DefaultItemAnimator());
rv.setAdapter(mFastItemAdapter);
//fill with some sample data
mFastItemAdapter.add(ImageDummyData.getImageItems());
//restore selections (this has to be done after the items were added
mFastItemAdapter.withSavedInstanceState(savedInstanceState);
//a custom OnCreateViewHolder listener class which is used to create the viewHolders
//we define the listener for the imageLovedContainer here for better performance
//you can also define the listener within the items bindView method but performance is better if you do it like this
mFastItemAdapter.withItemEvent(new ImageItem.ImageItemHeartClickEvent());
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
}
Aggregations