Created
January 13, 2018 02:18
-
-
Save gvr23/8a82d5773ad87a0f24e3bc11b6eaf156 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
ANDROID | |
=================================================================================================================================== | |
ADAPTER | |
=================================================================================================================================== | |
public class DocumentAdapter extends RecyclerView.Adapter<DocumentAdapter.ViewHolder>{ | |
private List<DocumentoBean> items; | |
public DocumentAdapter(List<DocumentoBean> items){ | |
this.items = items; | |
} | |
public void addItem(DocumentoBean item ){ | |
this.items.add(item); | |
notifyDataSetChanged(); | |
} | |
@Override | |
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { | |
View v = LayoutInflater.from(parent.getContext()) | |
.inflate(R.layout.document_row, parent, false); | |
return new DocumentAdapter.ViewHolder(v); | |
} | |
@Override | |
public void onBindViewHolder(ViewHolder holder, int position) { | |
DocumentoBean item = items.get(position); | |
holder.tvTipoDoc.setText((item.getCodTipoDoc() == null) ? "-" : item.getCodTipoDoc()); | |
holder.tvNumero.setText((item.getNumdoc() == null) ? "-" : item.getNumdoc()); | |
holder.tvCambio.setText((item.getTcambio() == null) ? "-" : item.getTcambio()); | |
holder.tvPorcAvance.setText((item.getPorcpago() == null) ? "-" : item.getPorcpago()); | |
holder.tvRecargo.setText((item.getRecargo() == null) ? "-" : item.getRecargo()); | |
holder.tvMonto.setText((item.getMbruto() == null) ? "-" : item.getMbruto()); | |
} | |
@Override | |
public int getItemCount() { | |
return items.size(); | |
} | |
class ViewHolder extends RecyclerView.ViewHolder{ | |
TextView tvTipoDoc; | |
TextView tvNumero; | |
TextView tvCambio; | |
TextView tvPorcAvance; | |
TextView tvRecargo; | |
TextView tvMonto; | |
public ViewHolder(View rootView) { | |
super(rootView); | |
tvTipoDoc = rootView.findViewById(R.id.tvTipoDoc); | |
tvNumero = rootView.findViewById(R.id.tvNumero); | |
tvCambio = rootView.findViewById(R.id.tvCambio); | |
tvPorcAvance = rootView.findViewById(R.id.tvPorcAvance); | |
tvRecargo = rootView.findViewById(R.id.tvRecargo); | |
tvMonto = rootView.findViewById(R.id.tvMonto); | |
} | |
} | |
} | |
================================================================================================================================= | |
EN LA VISTA DE EJECUCIÓN | |
================================================================================================================================= | |
private void setUpViews() { | |
mAdapter = new DocumentAdapter(new ArrayList<DocumentoBean>()); | |
rvItems.setLayoutManager(new LinearLayoutManager(getContext())); | |
rvItems.setAdapter(mAdapter); | |
} | |
================================================================================================================================= | |
XML | |
================================================================================================================================ | |
<android.support.v7.widget.RecyclerView | |
android:id="@+id/rvItems" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"/> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment