Skip to content

Instantly share code, notes, and snippets.

@codingpizza
Created December 11, 2017 21:02
Show Gist options
  • Save codingpizza/eedc55888d3847e7822e21734b837b06 to your computer and use it in GitHub Desktop.
Save codingpizza/eedc55888d3847e7822e21734b837b06 to your computer and use it in GitHub Desktop.
Aplicación #1 - PizzaListActivity con ItemClicklistener
public class PizzaListActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pizza_list);
RecyclerView recyclerView = findViewById(R.id.recycler_view);
List<Pizza> pizzaList = new ArrayList<>();
Pizza pizza_margherita = new Pizza("Margherita",R.drawable.pizza3,"Tomate,Mozzarella,Albahaca,sal,aceite");
pizzaList.add(pizza_margherita);
Pizza pizza_marinara = new Pizza("Marinara",R.drawable.pizza2,"Tomate,Aceite,Ajo y oregano");
pizzaList.add(pizza_marinara);
Pizza pizza_salciccia = new Pizza ("Pizza alle salciccia",R.drawable.pizza2,"Tomate,Mozzarella,Albahaca,aceite,salchichas");
pizzaList.add(pizza_salciccia);
CustomAdapter customAdapter = new CustomAdapter(pizzaList, new OnRecyclerViewItemClickListener() {
@Override
public void onItemClick(Pizza pizza_selected) {
Toast.makeText(PizzaListActivity.this, pizza_selected.getDescription(), Toast.LENGTH_SHORT).show();
}
});
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(this);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayoutManager.VERTICAL));
recyclerView.setAdapter(customAdapter);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment