Question

i am trying to add an OnItemClickListener to a coverflow app for android, one where the images can scroll back and forth and the part i wanted to add was an on click listener so you can click on one of the images and go to another activity. i am guessing that it works the same way you would if you were adding an OnItemClick to a listview or a gridview filled with images. I understand that this question has been asked before, however this case is different. there is additional code in the app that does not make sense. here is where the code comes from http://www.inter-fuser.com/2010/01/android-coverflow-widget.html and this app has the following four java classes:

CoverFlow.java // extends CoverAbsSpinner and implements GestureDetector.OnGestureListener

CoverAdapterView.java // class extends Adapter and ViewGroup classes

CoverAbsSpinner.java // this class extends CoverAdapterView.java

CoverFlowExample.java // extends Activity

and the strange thing is this code shown below that i found in the CoverAdapterView.java class. it does not make sense to place what looks like a useless interface stuck in the middle of the class. and it says "Callback method to be invoked when an item in this AdapterView has been clicked."

this is the mystery of the method. how do you "call" this? did they actually prepare the OnItemClickListener? do i override this thing or what?

and for the reason of this code in not yet understood? anyone know what the purpose of this is? it is an interface that you have to implement or override anyway. so i question the purpose of this.

public interface OnItemClickListener {

    /**
     * Callback method to be invoked when an item in this AdapterView has
     * been clicked.
     * <p>
     * Implementers can call getItemAtPosition(position) if they need
     * to access the data associated with the selected item.
     *
     * @param parent The AdapterView where the click happened.
     * @param view The view within the AdapterView that was clicked (this
     *            will be a view provided by the adapter)
     * @param position The position of the view in the adapter.
     * @param id The row id of the item that was clicked.
     */
    void onItemClick(CoverAdapterView<?> parent, View view, int position, long id);


}
/**
 * Register a callback to be invoked when an item in this AdapterView has
 * been clicked.
 *
 * @param listener The callback that will be invoked.
 */
public void setOnItemClickListener(OnItemClickListener listener) {
    mOnItemClickListener = listener;
}

/**
 * @return The callback to be invoked with an item in this AdapterView has
 *         been clicked, or null id no callback has been set.
 */
public final OnItemClickListener getOnItemClickListener() {
    return mOnItemClickListener;
}

/**
 * Call the OnItemClickListener, if it is defined.
 *
 * @param view The view within the AdapterView that was clicked.
 * @param position The position of the view in the adapter.
 * @param id The row id of the item that was clicked.
 * @return True if there was an assigned OnItemClickListener that was
 *         called, false otherwise is returned.
Was it helpful?

Solution

Hi for coverflow click listner try to use this.

coverFlow.setOnItemClickListener(new OnItemClickListener() 
{
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) 
    {
        switch(position) 
        {
            case 0:
                startActivity(new Intent(****.this,@@@@.class));
                finish();
                break;
            case 1:
                startActivity(new Intent(****.this, ####.class));
                finish();
                break;
            case 2:
                startActivity(new Intent(****.this, &&&&.class));
                finish();
                break;

        }
    }
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top