0
I have the following problem, I have a screen where I display a list using a Recyclerview, until then it works well, then when I use the view Scroll it creates "spaces" blank in the list ...
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 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>
Ask the question the Trainer code.
– ramaral
Probably your "parent" layout of the Adapter xml should be with match_parent instead of wrap_content at height. Post Adapter and xml code please.
– Mr_Anderson