MCPcopy Create free account
hub / github.com/NativeScript/NativeScript / refresh

Method refresh

packages/core/ui/list-view/index.android.ts:235–260  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

233 }
234
235 public refresh() {
236 const nativeView = this.nativeViewProtected;
237 if (!nativeView || !nativeView.getAdapter()) {
238 return;
239 }
240
241 // clear bindingContext when it is not observable because otherwise bindings to items won't reevaluate
242 this._realizedItems.forEach(({ view }, nativeView) => {
243 if (!(view.bindingContext instanceof Observable)) {
244 view.bindingContext = null;
245 }
246 });
247
248 // Safely refresh the adapter - no HeaderViewListAdapter issues since we don't use headers
249 const adapter = nativeView.getAdapter();
250 if (adapter instanceof android.widget.BaseAdapter) {
251 try {
252 adapter.notifyDataSetChanged();
253 } catch (error) {
254 if (Trace.isEnabled()) {
255 Trace.error('Error refreshing adapter, recreating: ' + error);
256 }
257 nativeView.setAdapter(new ListViewAdapterClass(this));
258 }
259 }
260 }
261
262 public scrollToIndex(index: number) {
263 const nativeView = this.nativeViewProtected;

Callers 1

Calls 3

forEachMethod · 0.80
isEnabledMethod · 0.80
errorMethod · 0.80

Tested by

no test coverage detected