Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8199783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:14:31+00:00 2026-06-07T06:14:31+00:00

I have created a BaseAdapter for a ListView. I want to order the elements

  • 0

I have created a “BaseAdapter” for a “ListView”. I want to order the elements in the list, so the constructor of my “BaseAdapter” receive an ordered array of the elements. But I don’t know why, the elements are not ordered properly.

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;
  }

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:14:32+00:00Added an answer on June 7, 2026 at 6:14 am

    I think your solution is complex. Make it easy. In your constructor copy the array, then sort it using a java.util.Comparator; with a condition. you will find many samples of Comparator exaple in this site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

HI Guyz i have created a sectioned custom listview using baseadapter its working fine
We have created custom listview by using the Base adapter. List view contains Text
I have a ListView with a custom list adapter (that extends BaseAdapter). My list
I have created the simple list view with base adapter.Now I want to add
I have created a custom listview and adapter by extending BaseAdapter. Every time I
I have created an app that I want to list all the installed applications
My problem is that I don't know whether I should use multiple list view
I have created a class of type BaseAdapter that is populated with buttons -
I have a ListView with an adapter extending BaseAdapter. I create a view (from
I have a straight forward BaseAdapter for my ListView. It downloads a JSON feed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.