Merche300
17/06/17, 16:37:22
Veran, estoy parseando datos desde un json:
[{"fecha": "Enviado el 17-06-2017 a las 10:19 horas",
"nombre": "benja",
"email": "[email protected]",
"agregado": "1",
"comentario": "Camp Reial de Montroi."
},
{"fecha": "Enviado el 17-06-2017 a las 10:19 horas",
"nombre": "Ramon",
"email": "[email protected]",
"agregado": "0",
"comentario": "Puesto el de Montroi"
},
{"fecha": "Enviado el 17-06-2017 a las 09:21 horas",
"nombre": "Ramon",
"email": "[email protected]",
"agregado": "1",
"comentario": "Aqui podeis pedir los campos y comentarios ."
}
]el cual en agregado me devuelbe 0 ó 1.
Mi intencion es que si me devuelve 0 me muestre un ImageView y si me devuelve 1 otro ImageView.
lo intento asi:
public class Comentarios_Adapter extends RecyclerView.Adapter<Comentarios_Adapter.ViewHolder> {
private ImageLoader imageLoader;
private Context context;
List<Estadisticas> estadisticas;
public Comentarios_Adapter(List<Estadisticas> estadisticas, Context context) {
super();
this.estadisticas = estadisticas;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from( parent.getContext() ).inflate( R.layout.comentarios_row, parent, false );
ViewHolder viewHolder = new ViewHolder( v );
return viewHolder;
}
public void onBindViewHolder(ViewHolder holder, final int position) {
holder.root.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(context, "this is my Toast message!!! =)",
//Toast.LENGTH_LONG).show();
//Toast.makeText(context, estadisticas.get(position).getNombrePlato(), Toast.LENGTH_SHORT).show();
/*Intent intent= new Intent(context, DetailCampos.class);
intent.putExtra("Nombre_campo", estadisticas.get(position).getNombre_campo());
intent.putExtra("Nombre", estadisticas.get(position).getEquipo());
intent.putExtra("Telefono", estadisticas.get(position).getTelefono());
intent.putExtra("Geo", estadisticas.get(position).getGeo());
intent.putExtra("Email", estadisticas.get(position).getEmail());
intent.putExtra("Url", estadisticas.get(position).getUrl());
intent.putExtra("Imagen", estadisticas.get(position).getEscudo());
context.startActivity(intent);*/
Estadisticas estadisticas1 = estadisticas.get(getAdapterPosition());
}
private int getAdapterPosition() {
return 0;
}
} );
Estadisticas campos = estadisticas.get( position );
imageLoader = DecoracionLineaDivisoria.CustomVolleyRequest.getIn stance(context ).getImageLoader();
holder.textViewFecha.setText( campos.getFecha() );
holder.textViewEquipo_Local.setText( campos.getEquipo() );
if ( campos.getEscudo() == "1") {
imageLoader.get(campos.getEscudo(), ImageLoader.getImageListener(holder.escudo_local, R.mipmap.ic_launcher, R.drawable.sol ) );
}
}
@Override
public int getItemCount() {
return estadisticas.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public ImageView escudo_local;
public TextView textViewEquipo_Local,textViewFecha;
public View root;
public ViewHolder(View itemView) {
super( itemView );
root = itemView;
escudo_local = (ImageView) itemView.findViewById( R.id.tv_esc_local );
textViewFecha = (TextView) itemView.findViewById( R.id.tv_fecha );
textViewEquipo_Local = (TextView) itemView.findViewById( R.id.tv_comentario );
}
}
public void setFilter(List<Estadisticas> countryModels) {
estadisticas = new ArrayList<>();
estadisticas.addAll(countryModels);
notifyDataSetChanged();
}
}Pero siempre me muestra la misma imagen que es:
<ImageView
android:id="@+id/tv_esc_local"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="left"
android:layout_weight="1"
android:padding="1dp"
card_view:srcCompat="@drawable/tick1"/>¿Como puedo conseguilo? Gracias
[{"fecha": "Enviado el 17-06-2017 a las 10:19 horas",
"nombre": "benja",
"email": "[email protected]",
"agregado": "1",
"comentario": "Camp Reial de Montroi."
},
{"fecha": "Enviado el 17-06-2017 a las 10:19 horas",
"nombre": "Ramon",
"email": "[email protected]",
"agregado": "0",
"comentario": "Puesto el de Montroi"
},
{"fecha": "Enviado el 17-06-2017 a las 09:21 horas",
"nombre": "Ramon",
"email": "[email protected]",
"agregado": "1",
"comentario": "Aqui podeis pedir los campos y comentarios ."
}
]el cual en agregado me devuelbe 0 ó 1.
Mi intencion es que si me devuelve 0 me muestre un ImageView y si me devuelve 1 otro ImageView.
lo intento asi:
public class Comentarios_Adapter extends RecyclerView.Adapter<Comentarios_Adapter.ViewHolder> {
private ImageLoader imageLoader;
private Context context;
List<Estadisticas> estadisticas;
public Comentarios_Adapter(List<Estadisticas> estadisticas, Context context) {
super();
this.estadisticas = estadisticas;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from( parent.getContext() ).inflate( R.layout.comentarios_row, parent, false );
ViewHolder viewHolder = new ViewHolder( v );
return viewHolder;
}
public void onBindViewHolder(ViewHolder holder, final int position) {
holder.root.setOnClickListener( new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(context, "this is my Toast message!!! =)",
//Toast.LENGTH_LONG).show();
//Toast.makeText(context, estadisticas.get(position).getNombrePlato(), Toast.LENGTH_SHORT).show();
/*Intent intent= new Intent(context, DetailCampos.class);
intent.putExtra("Nombre_campo", estadisticas.get(position).getNombre_campo());
intent.putExtra("Nombre", estadisticas.get(position).getEquipo());
intent.putExtra("Telefono", estadisticas.get(position).getTelefono());
intent.putExtra("Geo", estadisticas.get(position).getGeo());
intent.putExtra("Email", estadisticas.get(position).getEmail());
intent.putExtra("Url", estadisticas.get(position).getUrl());
intent.putExtra("Imagen", estadisticas.get(position).getEscudo());
context.startActivity(intent);*/
Estadisticas estadisticas1 = estadisticas.get(getAdapterPosition());
}
private int getAdapterPosition() {
return 0;
}
} );
Estadisticas campos = estadisticas.get( position );
imageLoader = DecoracionLineaDivisoria.CustomVolleyRequest.getIn stance(context ).getImageLoader();
holder.textViewFecha.setText( campos.getFecha() );
holder.textViewEquipo_Local.setText( campos.getEquipo() );
if ( campos.getEscudo() == "1") {
imageLoader.get(campos.getEscudo(), ImageLoader.getImageListener(holder.escudo_local, R.mipmap.ic_launcher, R.drawable.sol ) );
}
}
@Override
public int getItemCount() {
return estadisticas.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public ImageView escudo_local;
public TextView textViewEquipo_Local,textViewFecha;
public View root;
public ViewHolder(View itemView) {
super( itemView );
root = itemView;
escudo_local = (ImageView) itemView.findViewById( R.id.tv_esc_local );
textViewFecha = (TextView) itemView.findViewById( R.id.tv_fecha );
textViewEquipo_Local = (TextView) itemView.findViewById( R.id.tv_comentario );
}
}
public void setFilter(List<Estadisticas> countryModels) {
estadisticas = new ArrayList<>();
estadisticas.addAll(countryModels);
notifyDataSetChanged();
}
}Pero siempre me muestra la misma imagen que es:
<ImageView
android:id="@+id/tv_esc_local"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="left"
android:layout_weight="1"
android:padding="1dp"
card_view:srcCompat="@drawable/tick1"/>¿Como puedo conseguilo? Gracias