Doron Sinai
Doron Sinai

Reputation: 1186

Update activity listview from listener

I have a helper class to handle Network Service Discovery, where I declare the NsdManager.ResolveListener, once it resolves a service I want to update the Activity list view.

My Activity onStart

@Override
protected void onStart() {
    mNsdHelper = new NsdHelper(this);
    mNsdHelper.initializeNsd();
    super.onStart();
}

I want to update back the activity once the service is resolved:

    mResolveListener = new NsdManager.ResolveListener() {
        @Override
        public void onResolveFailed(NsdServiceInfo serviceInfo, int errorCode) {
            Log.e(TAG, "Resolve failed" + errorCode);
        }
        @Override
        public void onServiceResolved(NsdServiceInfo serviceInfo) {
            Log.e(TAG, "Resolve Succeeded. " + serviceInfo);
            mService = serviceInfo;
        }
    };

How do I do that?

Upvotes: 0

Views: 48

Answers (1)

Austin Hanson
Austin Hanson

Reputation: 22040

Use Activity.runOnUiThread(Runnable) to affect some change to your ListView Adapter's backing data model on the main thread. Afterwards, call Adapter.notifyDataSetChanged(). See How to refresh Android listview?

Upvotes: 1

Related Questions