Java Code Examples for android.widget.BaseAdapter#notifyDataSetChanged()

The following examples show how to use android.widget.BaseAdapter#notifyDataSetChanged() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppWidgetHostView.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Process data-changed notifications for the specified view in the specified
 * set of {@link RemoteViews} views.
 */
void viewDataChanged(int viewId) {
    View v = findViewById(viewId);
    if ((v != null) && (v instanceof AdapterView<?>)) {
        AdapterView<?> adapterView = (AdapterView<?>) v;
        Adapter adapter = adapterView.getAdapter();
        if (adapter instanceof BaseAdapter) {
            BaseAdapter baseAdapter = (BaseAdapter) adapter;
            baseAdapter.notifyDataSetChanged();
        }  else if (adapter == null && adapterView instanceof RemoteAdapterConnectionCallback) {
            // If the adapter is null, it may mean that the RemoteViewsAapter has not yet
            // connected to its associated service, and hence the adapter hasn't been set.
            // In this case, we need to defer the notify call until it has been set.
            ((RemoteAdapterConnectionCallback) adapterView).deferNotifyDataSetChanged();
        }
    }
}
 
Example 2
Source File: ContactsIndexView.java    From PinyinSearchLibrary with Apache License 2.0 6 votes vote down vote up
public void updateContactsList() {
	if (null == mIndexValueLv) {
		return;
	}

	BaseAdapter contactsAdapter = (BaseAdapter) mIndexValueLv.getAdapter();
	if (null != contactsAdapter) {
		contactsAdapter.notifyDataSetChanged();
		if (contactsAdapter.getCount() > 0) {

		} else {

		}

	}
}
 
Example 3
Source File: ContactsOperationView.java    From PinyinSearchLibrary with Apache License 2.0 6 votes vote down vote up
public void refreshContactsLv() {
	if (null == mContactsLv) {
		return;
	}
	
	ViewUtil.hideView(mContactsIndexView);
	
	BaseAdapter contactsAdapter = (BaseAdapter) mContactsLv.getAdapter();
	if (null != contactsAdapter) {
		contactsAdapter.notifyDataSetChanged();
		if (contactsAdapter.getCount() > 0) {
			ViewUtil.showView(mContactsLv);
			ViewUtil.hideView(mSearchResultPromptTv);

		} else {
			ViewUtil.hideView(mContactsLv);
			ViewUtil.showView(mSearchResultPromptTv);

		}
	}
}
 
Example 4
Source File: T9SearchFragment.java    From PinyinSearchLibrary with Apache License 2.0 6 votes vote down vote up
private void refreshT9SearchGv() {
	if (null == mT9SearchGv) {
		return;
	}

	BaseAdapter baseAdapter = (BaseAdapter) mT9SearchGv.getAdapter();
	Log.i(TAG, "getCount"+baseAdapter.getCount()+"");
	if (null != baseAdapter) {
		baseAdapter.notifyDataSetChanged();
		if (baseAdapter.getCount() > 0) {
			ViewUtil.showView(mT9SearchGv);
			ViewUtil.hideView(mSearchResultPromptTv);
		} else {
			ViewUtil.hideView(mT9SearchGv);
			ViewUtil.showView(mSearchResultPromptTv);
		}
	}
}
 
Example 5
Source File: QwertySearchFragment.java    From PinyinSearchLibrary with Apache License 2.0 6 votes vote down vote up
private void refreshQwertySearchGv() {
	if (null == mQwertySearchGv) {
		return;
	}

	BaseAdapter baseAdapter = (BaseAdapter) mQwertySearchGv.getAdapter();
	Log.i(TAG, "getCount"+baseAdapter.getCount()+"");
	if (null != baseAdapter) {
		baseAdapter.notifyDataSetChanged();
		if (baseAdapter.getCount() > 0) {
			ViewUtil.showView(mQwertySearchGv);
			ViewUtil.hideView(mSearchResultPromptTv);
		} else {
			ViewUtil.hideView(mQwertySearchGv);
			ViewUtil.showView(mSearchResultPromptTv);
		}
	}
}
 
Example 6
Source File: AbstractViewQuery.java    From COCOQuery with Apache License 2.0 6 votes vote down vote up
/**
 * Notify a ListView that the data of it's adapter is changed.
 *
 * @return self
 */
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();
}
 
Example 7
Source File: MainApp.java    From NetKnight with Apache License 2.0 5 votes vote down vote up
@Override
public void onLoadAppInfoList(BaseAdapter adapter) {
    Log.d("MainApp", "加载数据咯");
    app_listView.setAdapter(adapter);

    adapter.notifyDataSetChanged();
}
 
Example 8
Source File: FanfouServiceManager.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
public static void doFavorite(final Activity activity, final Status s,
        final BaseAdapter adapter) {
    final ActionResultHandler li = new ActionResultHandler() {
        @Override
        public void onActionSuccess(final int type, final String message) {
            if (type == Constants.TYPE_FAVORITES_CREATE) {
                s.favorited = true;
            } else {
                s.favorited = false;
            }
            adapter.notifyDataSetChanged();
        }
    };
    FanfouServiceManager.doFavorite(activity, s, li);
}
 
Example 9
Source File: UIManager.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
public static void doDelete(final Activity activity, final Status s,
        final BaseAdapter adapter) {
    final ActionResultHandler li = new ActionResultHandler() {
        @Override
        public void onActionSuccess(final int type, final String message) {
            adapter.notifyDataSetChanged();
        }
    };
    FanfouServiceManager.doStatusDelete(activity, s.id, li);
}
 
Example 10
Source File: UIManager.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
public static void doDelete(final Activity activity, final Status s,
        final BaseAdapter adapter, final List<Status> ss) {
    final ActionResultHandler li = new ActionResultHandler() {
        @Override
        public void onActionSuccess(final int type, final String message) {
            ss.remove(s);
            adapter.notifyDataSetChanged();
        }
    };
    FanfouServiceManager.doStatusDelete(activity, s.id, li);
}
 
Example 11
Source File: BaseRecipientAdapter.java    From talk-android with MIT License 4 votes vote down vote up
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
        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);
}
 
Example 12
Source File: HandlerFactory.java    From wakao-app with MIT License 4 votes vote down vote up
public static Handler createListviewHandler(
		final PullToRefreshListView listview,
		final LinearLayout footerLayout, final BaseAdapter adapter) {
	return new Handler() {
		
		TextView tv = (TextView) footerLayout
				.findViewById(R.id.listview_foot_more);
		ProgressBar bar = (ProgressBar) footerLayout
				.findViewById(R.id.listview_foot_progress);

		@Override
		public void handleMessage(Message msg) {
			Log.i("TAG", "dealing...code:"+ msg.what);
			switch (msg.what) {
			case MyRobot.IS_NETWORK_LOADING:
				bar.setVisibility(View.VISIBLE);
				tv.setText("正在加载...");
				break;
			case MyRobot.IS_REFRESH_COMPLETE:
				adapter.notifyDataSetChanged();
				listview.setSelection(0);
				listview.onRefreshComplete(pull_to_refresh_update
						+ new Date().toLocaleString());
				bar.setVisibility(View.GONE);
				tv.setText("上拉松开加载更多");
				break;
			case MyRobot.IS_GETMORE_COMPLETE:
				adapter.notifyDataSetChanged();
				bar.setVisibility(View.GONE);
				tv.setText("上拉松开加载更多");
				break;
			case MyRobot.IS_NETWORK_ERROR:
				Toast.makeText(listview.getContext(), "网络连接失败",
						Toast.LENGTH_SHORT).show();
				break;
			case MyRobot.IS_REFRESH_ERROR:
				Toast.makeText(listview.getContext(), "数据刷新失败",
						Toast.LENGTH_SHORT).show();
				listview.setSelection(0);
				listview.onRefreshComplete(pull_to_refresh_update
						+ new Date().toLocaleString());
				break;
			case MyRobot.IS_GETMORE_ERROR:
				Toast.makeText(listview.getContext(), "网络连接失败",
						Toast.LENGTH_SHORT).show();
				bar.setVisibility(View.GONE);
				tv.setText("点击刷新");
				break;
			case MyRobot.LOAD_DATA_ALL:
				bar.setVisibility(View.GONE);
				tv.setText("没有更多数据了");
				break;
			case MyRobot.CLEAR_DATA:
				adapter.notifyDataSetChanged();
				break;
			default:
				Log.i("TAG", msg.what+ "no deal...");
				break;
			}
		}

	};
}
 
Example 13
Source File: NetAppUse.java    From NetKnight with Apache License 2.0 3 votes vote down vote up
@Override
public void onLoadAppInfoUseList(BaseAdapter adapter) {
    appuse_listView.setAdapter(adapter);

    adapter.notifyDataSetChanged();


}