Example usage for android.widget AdapterView setOnItemClickListener

List of usage examples for android.widget AdapterView setOnItemClickListener

Introduction

In this page you can find the example usage for android.widget AdapterView setOnItemClickListener.

Prototype

public void setOnItemClickListener(@Nullable OnItemClickListener listener) 

Source Link

Document

Register a callback to be invoked when an item in this AdapterView has been clicked.

Usage

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

/**
 * Register a callback method for when an item is clicked in the ListView.
 * @param listener The callback method./* www .  j  ava  2  s . co m*/
 * @return self
 */
public T itemClicked(OnItemClickListener listener) {
    if (view instanceof AdapterView) {
        AdapterView<?> alv = (AdapterView<?>) view;
        alv.setOnItemClickListener(listener);
    }
    return self();
}

From source file:com.androidquery.AQuery.java

/**
 * Register a callback method for when an item is clicked in the ListView.
 *
 * @param listener The callback method./*from  w ww . j  a va 2 s .co m*/
 * @return self
 */
public AQuery itemClicked(OnItemClickListener listener) {

    if (view instanceof AdapterView) {

        AdapterView<?> alv = (AdapterView<?>) view;
        alv.setOnItemClickListener(listener);

    }

    return self();

}

From source file:com.androidquery.AbstractAQuery.java

/**
 * Register a callback method for when an item is clicked in the ListView.
 *
 * @param listener The callback method.//from   www. ja v  a  2s  .  c o m
 * @return self
 */
public T itemClicked(OnItemClickListener listener) {

    if (view instanceof AdapterView) {

        AdapterView<?> alv = (AdapterView<?>) view;
        alv.setOnItemClickListener(listener);

    }

    return self();

}

From source file:com.brandroidtools.filemanager.fragments.NavigationFragment.java

/**
 * Method that change the view mode./* ww  w. j a  v  a  2 s  .c om*/
 *
 * @param newMode The new mode
 */
@SuppressWarnings({ "unchecked", "null" })
public void changeViewMode(final NavigationLayoutMode newMode) {
    synchronized (this.mSync) {
        //Check that it is really necessary change the mode
        if (this.mCurrentMode != null && this.mCurrentMode.compareTo(newMode) == 0) {
            return;
        }

        // If we should set the listview to response to flinger gesture detection
        boolean useFlinger = Preferences.getSharedPreferences().getBoolean(
                FileManagerSettings.SETTINGS_USE_FLINGER.getId(),
                ((Boolean) FileManagerSettings.SETTINGS_USE_FLINGER.getDefaultValue()).booleanValue());

        //Creates the new layout
        AdapterView<ListAdapter> newView = null;
        int itemResourceId = -1;
        if (newMode.compareTo(NavigationLayoutMode.ICONS) == 0) {
            newView = (AdapterView<ListAdapter>) mNavigationViewHolder.inflate(mActivity,
                    RESOURCE_MODE_ICONS_LAYOUT, null);
            itemResourceId = RESOURCE_MODE_ICONS_ITEM;

        } else if (newMode.compareTo(NavigationLayoutMode.SIMPLE) == 0) {
            newView = (AdapterView<ListAdapter>) mNavigationViewHolder.inflate(mActivity,
                    RESOURCE_MODE_SIMPLE_LAYOUT, null);
            itemResourceId = RESOURCE_MODE_SIMPLE_ITEM;

            // Set the flinger listener (only when navigate)
            if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
                if (useFlinger && newView instanceof FlingerListView) {
                    ((FlingerListView) newView).setOnItemFlingerListener(this.mOnItemFlingerListener);
                }
            }

        } else if (newMode.compareTo(NavigationLayoutMode.DETAILS) == 0) {
            newView = (AdapterView<ListAdapter>) mNavigationViewHolder.inflate(mActivity,
                    RESOURCE_MODE_DETAILS_LAYOUT, null);
            itemResourceId = RESOURCE_MODE_DETAILS_ITEM;

            // Set the flinger listener (only when navigate)
            if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
                if (useFlinger && newView instanceof FlingerListView) {
                    ((FlingerListView) newView).setOnItemFlingerListener(this.mOnItemFlingerListener);
                }
            }
        }

        //Get the current adapter and its adapter list
        List<FileSystemObject> files = new ArrayList<FileSystemObject>(this.mFiles);
        final AdapterView<ListAdapter> current = (AdapterView<ListAdapter>) getView()
                .findViewById(RESOURCE_CURRENT_LAYOUT);
        FileSystemObjectAdapter adapter = new FileSystemObjectAdapter(mActivity,
                new ArrayList<FileSystemObject>(), itemResourceId,
                this.mNavigationMode.compareTo(NAVIGATION_MODE.PICKABLE) == 0);
        adapter.setOnSelectionChangedListener(this);

        //Remove current layout
        if (current != null) {
            if (current.getAdapter() != null) {
                //Save selected items before dispose adapter
                FileSystemObjectAdapter currentAdapter = ((FileSystemObjectAdapter) current.getAdapter());
                adapter.setSelectedItems(currentAdapter.getSelectedItems());
                currentAdapter.dispose();
            }
            mNavigationViewHolder.removeView(current);
        }
        this.mFiles = files;
        adapter.addAll(files);
        adapter.notifyDataSetChanged();

        //Set the adapter
        this.mAdapter = adapter;
        newView.setAdapter(this.mAdapter);
        newView.setOnItemClickListener(NavigationFragment.this);

        //Add the new layout
        this.mAdapterView = newView;
        mNavigationViewHolder.addView(newView, 0);
        this.mCurrentMode = newMode;

        // Pick mode doesn't implements the onlongclick
        if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
            this.mAdapterView.setOnItemLongClickListener(this);
        } else {
            this.mAdapterView.setOnItemLongClickListener(null);
        }

        //Save the preference (only in navigation browse mode)
        if (this.mNavigationMode.compareTo(NAVIGATION_MODE.BROWSABLE) == 0) {
            try {
                Preferences.savePreference(FileManagerSettings.SETTINGS_LAYOUT_MODE, newMode, true);
            } catch (Exception ex) {
                Log.e(TAG, "Save of view mode preference fails", ex); //$NON-NLS-1$
            }
        }
    }
}