「ListView」の「BaseAdapter」を作成しました。リスト内の要素を順序付けしたいので、「BaseAdapter」のコンストラクターは要素の順序付けられた配列を受け取ります。しかし、理由はわかりません。要素が適切に並べられていません。
public class NotificacionesAdapter extends BaseAdapter
{
private LayoutInflater inflater;
private NotificacionInfo[] notificaciones = null;
static class ViewHolder
{
TextView titulo;
TextView mensaje;
TextView fecha;
}
public static class NotificacionInfo implements Comparable<NotificacionInfo>
{
private String titulo;
private String mensaje;
private Date fecha;
public NotificacionInfo()
{
}
public String getTitulo()
{
return titulo;
}
public void setTitulo(String titulo)
{
this.titulo = titulo;
}
public String getMensaje()
{
return mensaje;
}
public void setMensaje(String mensaje)
{
this.mensaje = mensaje;
}
public Date getFecha()
{
return fecha;
}
public void setFecha(Date fecha)
{
this.fecha = fecha;
}
@Override
public int compareTo(NotificacionInfo another)
{
return another.getFecha().compareTo(this.fecha);
}
}
public NotificacionesAdapter(Context context, NotificacionInfo[] notificaciones)
{
this.inflater = LayoutInflater.from(context);
this.notificaciones = notificaciones;
Arrays.sort(this.notificaciones);
System.out.println ();
}
@Override
public int getCount()
{
return this.notificaciones.length;
}
@Override
public Object getItem(int arg0)
{
return notificaciones[arg0];
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if (convertView == null)
{
convertView = inflater.inflate(R.layout.t_notificacion, null);
holder = new ViewHolder();
holder.titulo = (TextView) convertView.findViewById(R.id.titulo);
holder.mensaje = (TextView) convertView.findViewById(R.id.mensaje);
holder.fecha = (TextView) convertView.findViewById(R.id.fecha);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
holder.titulo.setText(notificaciones[position].getTitulo());
holder.mensaje.setText(notificaciones[position].getMensaje());
holder.fecha.setText(DateUtil.formatDate(notificaciones[position].getFecha(), "HH:mm dd-MM-yyyy"));
return convertView;
}
public void setNotificaciones (NotificacionInfo[] notificaciones)
{
Arrays.sort(this.notificaciones);
this.notificaciones = notificaciones;
}
前もって感謝します