update AdapterView Selection - Android User Interface

Android examples for User Interface:AdapterView

Description

update AdapterView Selection

Demo Code


//package com.java2s;
import android.util.Log;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;

public class Main {
    public static void updateSelection(final AdapterView<?> view,
            int selection, final OnItemSelectedListener listener) {
        view.setOnItemSelectedListener(null);
        view.setSelection(selection);//ww w.jav a 2 s . c o m
        view.post(new Runnable() {

            @Override
            public void run() {
                if (listener != null) {
                    Log.d("SelectionWidget", "Resetting listener");
                    view.setOnItemSelectedListener(listener);
                } else {
                    Log.d("SelectionWidget",
                            "Listener was NULL, not resetting");
                }

            }
        });
    }
}

Related Tutorials