Question

The aim of my app is to search for a song (deezer sdk)and display the result of the search in a gridView. I want to be able to have the cover of the album and the "artist - title" just below. As the "artist-title" may sometime be very long, I want to be able to scroll it horizontally. I've seen on the internet that I had to set the item as "focusable=false" but that doesn't seem to change anything. The XML of the items inside my gridview looks like this :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView_topLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >

<ImageView
    android:id="@+id/gridView_image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:contentDescription="@string/gridTextView_Album"
    android:src="@drawable/album_cover_default" />

<HorizontalScrollView
    android:id="@+id/gridView_horizontalScroll"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="left"
    android:clipChildren="true"
    android:fillViewport="true"
    android:scrollbars="none" >

    <RelativeLayout
        android:id="@+id/gridView_layout"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusableInTouchMode="false" >

        <TextView
            android:id="@+id/gridView_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:isScrollContainer="true"
            android:singleLine="true" />
    </RelativeLayout>
</HorizontalScrollView>

I know that is probably not the best way to do it but that's the only way I've managed to do it. My adapter works perfectly as the album's cover are displayed as intended and the artist-title works great too.

This is the setOnItemClickListener inside my activity:

gridview.setAdapter(songSelection_adapter_listAdapter);
gridview.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3)
{
    Log.i("onItemClickListener", "CLICK!");
}
});

This doesn't ever print "click!" in the logcat, nothing happens. I've tried with a "onTouchListener", which works great but I can't scroll my gridView down :(

Thank you for your help.

Was it helpful?

Solution

Set ItemClickListener for items of GridView in it's adapter,instead of set an ItemClickListener directly for GridView.

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