mardi 4 août 2015

notifyDataSetChanged method is not refreshing listview using updated data?

I am using an ArrayAdapter with filterable interface to implement search functionality in a listview.My code for adapter is following:

public class FlightsAdapter extends ArrayAdapter<Flight> implements Filterable {

    List<Flight> flightLists = new ArrayList<Flight>();
    private List<Flight> origFlightList;
    private Context context;
    Flight flight = null;

    public FlightsAdapter(Context context, int textViewResourceId,
            List<Flight> fLists) {
        super(context, textViewResourceId, fLists);
        this.context = context;
        this.flightLists = fLists;
    }

    public void updateFlightList(List<Flight> newData){
        this.flightLists.clear();
        this.flightLists = newData;

    }
public Filter getFilter() {
        return new Filter() {

            @Override
            protected FilterResults performFiltering(CharSequence constraint) {
                final FilterResults oReturn = new FilterResults();
                final List<Flight> results = new ArrayList<Flight>();
                if (origFlightList == null)
                    origFlightList = flightLists;
                if (constraint != null) {
                    if (origFlightList != null && origFlightList.size() > 0) {
                        for (final Flight f : origFlightList) {
                            if (f.getPlace().toLowerCase()
                                    .contains(constraint.toString()))
                                results.add(f);
                        }
                    }
                    oReturn.values = results;
                    oReturn.count = results.size();
                }
                return oReturn;
            }

            @SuppressWarnings("unchecked")
            @Override
            protected void publishResults(CharSequence constraint,
                                          FilterResults results) {
                flightLists = (ArrayList<Flight>) results.values;
                notifyDataSetChanged();
            }
        };
    }

}

getFilter() and publishResults() methods get triggered properly on searching and flightLists get populated with new data but the listview remain same with no items change, I don't know what I am doing wrong in above code, Please help me figure out this problem



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire