private RecyclerView recyclerView;
private TreinoAdapter mAdapter;
private List<Treino> treinos;
private Long idCliente;
private String escolhaSelect;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
recyclerView = (RecyclerView) findViewById(R.id.recycle);
}
/***
* Adiciona o menu setting
* @param menu
* @return
*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
String tipoEscolhido = (String) item.getTitle();
if( tipoEscolhido.equalsIgnoreCase("Realizar") )
this.escolhaSelect = "AR";
else if( tipoEscolhido.equalsIgnoreCase("Realizado") )
this.escolhaSelect = "S";
else
this.escolhaSelect = "N";
this.idCliente = ((long) 1);
retornaTreinos();
return true;
}
/**
* Método que abastece o RecycleView após a escolha do Item
* */
public void abasteceRecyclerView(){
mAdapter = new TreinoAdapter(treinos, this);
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(mAdapter);
recyclerView.addOnItemTouchListener(new RecycleTouchListener(
getApplicationContext(),
recyclerView,
new RecycleTouchListener.ClickListener() {
@Override
public void onClick(View view, int position) {
Treino treino = treinos.get(position);
Intent intent = new Intent(PrincipalActivity.this, DetalheActivity.class);
Bundle bundle = new Bundle();
String tipoTreino = "";
String terreno = "";
if(treino.getTipo().equalsIgnoreCase("T")){
tipoTreino = "Bike";
if(treino.getTerreno().equalsIgnoreCase("T"))
bundle.putString("terreno", "Terra");
else
bundle.putString("terreno", "Alsfalto");
}
else if(treino.getTipo().equalsIgnoreCase("M"))
tipoTreino = "Musculação";
else
tipoTreino = "Descanso";
bundle.putString("data", treino.getDataTreino());
bundle.putString("tipoTreino", tipoTreino);
bundle.putString("descricao", treino.getDescricao());
intent.putExtras(bundle);
startActivity(intent);
/*Toast.makeText(getApplicationContext(), "Exibindo Detalhe",//treino.getDescricao()
Toast.LENGTH_LONG).show();*/
public class TreinoAdapter extends RecyclerView.Adapter {
private List<Treino> treinos;
private Context context;
public TreinoAdapter(List<Treino> treinos, Context context){
this.treinos = treinos;
this.context = context;
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
TreinoViewHolder treinoViewHolder = new TreinoViewHolder(view);
return treinoViewHolder;
}
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
TreinoViewHolder treinoViewHolder = (TreinoViewHolder) holder;
treinoViewHolder.dataTreino.setText(treinos.get(position).getDataTreino());
treinoViewHolder.descricao.setText(treinos.get(position).getDescricao());
}
@Override
public int getItemCount() {
return this.treinos.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder{
TextView dataTreino;
TextView descricao;
public MyViewHolder(View itemView) {
super(itemView);
dataTreino = (TextView) itemView.findViewById(R.id.diaTreino);
descricao = (TextView) itemView.findViewById(R.id.descricao);
}
}
}
The Activity that receives the Recycler
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_principal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="PrincipalActivity">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/recycle"
android:scrollbars="vertical"/>
</RelativeLayout>