Example usage for android.widget BaseAdapter notifyDataSetChanged

List of usage examples for android.widget BaseAdapter notifyDataSetChanged

Introduction

In this page you can find the example usage for android.widget BaseAdapter notifyDataSetChanged.

Prototype

public void notifyDataSetChanged() 

Source Link

Document

Notifies the attached observers that the underlying data has been changed and any View reflecting the data set should refresh itself.

Usage

From source file:com.juick.android.MessageMenu.java

private void actionTranslateMessage() {
    String body = listSelectedItem.Text;
    translateToRussian(body, new Utils.Function<Void, String[]>() {
        @Override/* w w  w .  j  a va 2 s.  c  o m*/
        public Void apply(String ss[]) {
            StringBuilder sb = new StringBuilder();
            int successes = 0;
            for (String s : ss) {
                if (s == null)
                    continue;
                try {
                    JSONObject json = new JSONObject(s);
                    JSONArray sentences = json.getJSONArray("sentences");
                    if (sentences != null && sentences.length() > 0) {
                        s = sentences.getJSONObject(0).getString("trans");
                        if (s == null) {
                            sb.append("[error]");
                        } else {
                            successes++;
                            sb.append(s);
                            sb.append(". ");
                        }
                    } else {
                        sb.append("[error]");
                    }
                } catch (JSONException e) {

                }
            }
            if (successes > 0) {
                listSelectedItem.Text = sb.toString();
                listSelectedItem.parsedText = null;
                listSelectedItem.translated = true;
                //Parcelable parcelable = listView.onSaveInstanceState();
                BaseAdapter adapter = (BaseAdapter) unwrapAdapter(listView.getAdapter());
                adapter.notifyDataSetChanged();
            } else {
                Toast.makeText(activity, "Error translating..", Toast.LENGTH_LONG).show();
            }
            return null;
        }
    });
}

From source file:org.runnerup.view.DetailActivity.java

void requery() {
    {/*from  w  w w.  j a va2 s.  co  m*/
        /**
         * Laps
         */
        String[] from = new String[] { "_id", DB.LAP.LAP, DB.LAP.INTENSITY, DB.LAP.TIME, DB.LAP.DISTANCE,
                DB.LAP.PLANNED_TIME, DB.LAP.PLANNED_DISTANCE, DB.LAP.PLANNED_PACE, DB.LAP.AVG_HR };

        Cursor c = mDB.query(DB.LAP.TABLE, from, DB.LAP.ACTIVITY + " == " + mID, null, null, null, "_id", null);

        laps = DBHelper.toArray(c);
        c.close();
        lapHrPresent = false;
        for (ContentValues v : laps) {
            if (v.containsKey(DB.LAP.AVG_HR) && v.getAsInteger(DB.LAP.AVG_HR) > 0) {
                lapHrPresent = true;
                break;
            }
        }
    }

    {
        /**
         * Accounts/reports
         */
        String sql = new String("SELECT DISTINCT " + "  acc._id, " // 0
                + ("  acc." + DB.ACCOUNT.NAME + ", ") + ("  acc." + DB.ACCOUNT.DESCRIPTION + ", ")
                + ("  acc." + DB.ACCOUNT.FLAGS + ", ") + ("  acc." + DB.ACCOUNT.AUTH_METHOD + ", ")
                + ("  acc." + DB.ACCOUNT.AUTH_CONFIG + ", ") + ("  acc." + DB.ACCOUNT.ENABLED + ", ")
                + ("  rep._id as repid, ") + ("  rep." + DB.EXPORT.ACCOUNT + ", ")
                + ("  rep." + DB.EXPORT.ACTIVITY + ", ") + ("  rep." + DB.EXPORT.STATUS)
                + (" FROM " + DB.ACCOUNT.TABLE + " acc ") + (" LEFT OUTER JOIN " + DB.EXPORT.TABLE + " rep ")
                + (" ON ( acc._id = rep." + DB.EXPORT.ACCOUNT)
                + ("     AND rep." + DB.EXPORT.ACTIVITY + " = " + mID + " )")
                + (" WHERE acc." + DB.ACCOUNT.ENABLED + " != 0 ")
                + ("   AND acc." + DB.ACCOUNT.AUTH_CONFIG + " is not null"));

        Cursor c = mDB.rawQuery(sql, null);
        alreadyUploadedUploaders.clear();
        pendingUploaders.clear();
        reports.clear();
        if (c.moveToFirst()) {
            do {
                ContentValues tmp = DBHelper.get(c);
                Uploader uploader = uploadManager.add(tmp);
                if (!uploader.checkSupport(Feature.UPLOAD)) {
                    continue;
                }

                reports.add(tmp);
                if (tmp.containsKey("repid")) {
                    alreadyUploadedUploaders.add(tmp.getAsString(DB.ACCOUNT.NAME));
                } else if (tmp.containsKey(DB.ACCOUNT.FLAGS)
                        && Bitfield.test(tmp.getAsLong(DB.ACCOUNT.FLAGS), DB.ACCOUNT.FLAG_UPLOAD)) {
                    pendingUploaders.add(tmp.getAsString(DB.ACCOUNT.NAME));
                }
            } while (c.moveToNext());
        }
        c.close();
    }

    if (mode == MODE_DETAILS) {
        if (pendingUploaders.isEmpty()) {
            uploadButton.setVisibility(View.GONE);
        } else {
            uploadButton.setVisibility(View.VISIBLE);
        }
    }

    for (BaseAdapter a : adapters) {
        a.notifyDataSetChanged();
    }
}

From source file:com.benefit.buy.library.http.query.AbstractAQuery.java

/**
 * Notify a ListView that the data of it's adapter is changed.
 * @return self/*w w  w  . j a va  2 s . com*/
 */
public T dataChanged() {
    if (view instanceof AdapterView) {
        AdapterView<?> av = (AdapterView<?>) view;
        Adapter a = av.getAdapter();
        if (a instanceof BaseAdapter) {
            BaseAdapter ba = (BaseAdapter) a;
            ba.notifyDataSetChanged();
        }
    }
    return self();
}

From source file:com.github.shareme.gwschips.library.BaseRecipientAdapter.java

private static void fetchPhotoAsync(final RecipientEntry entry, final Uri photoThumbnailUri,
        final BaseAdapter adapter, final ContentResolver mContentResolver) {
    final AsyncTask<Void, Void, byte[]> photoLoadTask = new AsyncTask<Void, Void, byte[]>() {
        @Override//w  w  w.  java2  s  .  c  om
        protected byte[] doInBackground(Void... params) {
            // First try running a query. Images for local contacts are
            // loaded by sending a query to the ContactsProvider.
            final Cursor photoCursor = mContentResolver.query(photoThumbnailUri, PhotoQuery.PROJECTION, null,
                    null, null);
            if (photoCursor != null) {
                try {
                    if (photoCursor.moveToFirst()) {
                        return photoCursor.getBlob(PhotoQuery.PHOTO);
                    }
                } finally {
                    photoCursor.close();
                }
            } else {
                // If the query fails, try streaming the URI directly.
                // For remote directory images, this URI resolves to the
                // directory provider and the images are loaded by sending
                // an openFile call to the provider.
                try {
                    InputStream is = mContentResolver.openInputStream(photoThumbnailUri);
                    if (is != null) {
                        byte[] buffer = new byte[BUFFER_SIZE];
                        ByteArrayOutputStream baos = new ByteArrayOutputStream();
                        try {
                            int size;
                            while ((size = is.read(buffer)) != -1) {
                                baos.write(buffer, 0, size);
                            }
                        } finally {
                            is.close();
                        }
                        return baos.toByteArray();
                    }
                } catch (IOException ex) {
                    // ignore
                }
            }
            return null;
        }

        @Override
        protected void onPostExecute(final byte[] photoBytes) {
            entry.setPhotoBytes(photoBytes);
            if (photoBytes != null) {
                mPhotoCacheMap.put(photoThumbnailUri, photoBytes);
                if (adapter != null)
                    adapter.notifyDataSetChanged();
            }
        }
    };
    photoLoadTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}

From source file:com.androidquery.AQuery.java

/**
 * Notify a ListView that the data of it's adapter is changed.
 *
 * @return self//from   w w  w . j a v  a 2  s  .c o m
 */
public AQuery dataChanged() {

    if (view instanceof AdapterView) {

        AdapterView<?> av = (AdapterView<?>) view;
        Adapter a = av.getAdapter();

        if (a instanceof BaseAdapter) {
            BaseAdapter ba = (BaseAdapter) a;
            ba.notifyDataSetChanged();
        }

    }

    return self();
}

From source file:com.androidquery.AbstractAQuery.java

/**
 * Notify a ListView that the data of it's adapter is changed.
 *
 * @return self/*  w  w  w .  j a  v  a  2s .co  m*/
 */
public T dataChanged() {

    if (view instanceof AdapterView) {

        AdapterView<?> av = (AdapterView<?>) view;
        Adapter a = av.getAdapter();

        if (a instanceof BaseAdapter) {
            BaseAdapter ba = (BaseAdapter) a;
            ba.notifyDataSetChanged();
        }

    }

    return self();
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void selectAllVpn() {
    BaseAdapter adapter = (BaseAdapter) listview.getAdapter();
    int count = adapter.getCount();
    for (int item = 0; item < count; item++) {
        DroidApp app = (DroidApp) adapter.getItem(item);
        app.selected_vpn = true;//from w w w.  j  av a 2  s .co  m
        this.dirty = true;
    }
    adapter.notifyDataSetChanged();
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void selectAllLan() {
    BaseAdapter adapter = (BaseAdapter) listview.getAdapter();
    int count = adapter.getCount();
    for (int item = 0; item < count; item++) {
        DroidApp app = (DroidApp) adapter.getItem(item);
        app.selected_lan = true;// w  w w.  ja  va2  s . c om
        this.dirty = true;
    }
    adapter.notifyDataSetChanged();
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

/**
 * The following functions are for selecting all of a certain rule
 *///  w  ww  . j a v a 2 s .  c  om

private void selectAllData() {
    BaseAdapter adapter = (BaseAdapter) listview.getAdapter();
    int count = adapter.getCount();
    for (int item = 0; item < count; item++) {
        DroidApp app = (DroidApp) adapter.getItem(item);
        app.selected_3g = true;
        this.dirty = true;
    }
    adapter.notifyDataSetChanged();
}

From source file:com.jtschohl.androidfirewall.MainActivity.java

private void selectAllWiFi() {
    BaseAdapter adapter = (BaseAdapter) listview.getAdapter();
    int count = adapter.getCount();
    for (int item = 0; item < count; item++) {
        DroidApp app = (DroidApp) adapter.getItem(item);
        app.selected_wifi = true;//w  w w  .ja v a  2  s  . com
        this.dirty = true;
    }
    adapter.notifyDataSetChanged();
}