Android Open Source - Weather Auto Complete Cursor Adapter






From Project

Back to project page Weather.

License

The source code is released under:

Apache License

If you think the Android project Weather listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.volitic.weather;
/* w w w  .  j a  va  2  s  .com*/
import android.content.Context;
import android.database.Cursor;
import android.widget.Filter;
import android.widget.SimpleCursorAdapter;


public class AutoCompleteCursorAdapter extends SimpleCursorAdapter {

    DatabaseHelper mDatabaseHelper;

    public AutoCompleteCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) {
        super(context, layout, c, from, to, flags);
        mDatabaseHelper = new DatabaseHelper(context);
    }

    @Override
    public CharSequence convertToString(Cursor cursor) {
        return super.convertToString(cursor);
    }



    @Override
    public Filter getFilter()
    {
        return new Filter()
        {
            @Override
            protected void publishResults(CharSequence constraint, FilterResults results)
            {
                changeCursor((Cursor)results.values);
                if (results.count > 0)
                {
                    notifyDataSetChanged();
                }
                else
                {
                    notifyDataSetInvalidated();
                }
            }

            @Override
            protected FilterResults performFiltering(CharSequence constraint)
            {
                FilterResults fr = new FilterResults();

                Cursor cursor;
                if( constraint != null && constraint.length() > 0){
                    cursor =  mDatabaseHelper.getLocationFilteredBy(constraint);
                } else {
                    cursor = mDatabaseHelper.getAllLocations();
                }
                fr.values = cursor;
                fr.count = cursor.getCount();

                return fr;
            }
        };
    }

}




Java Source Code List

com.volitic.weather.AboutDialog.java
com.volitic.weather.AutoCompleteCursorAdapter.java
com.volitic.weather.AutoCompletePreference.java
com.volitic.weather.DatabaseHelper.java
com.volitic.weather.MainActivity.java
com.volitic.weather.Network.java
com.volitic.weather.SettingsActivity.java
com.volitic.weather.Time.java
com.volitic.weather.Weather.java
com.volitic.weather.XmlParser.java