sephiroth74/HorizontalVariableListView

OnItemClicked doesn't fire

Closed this issue · 7 comments

Hey all,

First of all, i want to thank you Alessandro for this lovely component. I have also tested the dev-smart's HorizontalListView, and i am getting much better results with your view.

Unfortunately though, I am suffering from one main problem - while i can scroll nice and smooth, i can't catch onItemClicked events. I have followed the example you've provided in the demo activity. More frustrating is the fact that when i test the same views and layouts i am using, with android's native ListView, and dev-smart's HLV it actually works. I made sure i was using the correct classed, but still can't get it to work.

Would appreciate if you guys could take a look at my code, and see whether i am doing something terribly catastrophic. After looking at it for the entire day, i am positive i am missing something very fundamental

The element view:

<ImageView 
    android:id="@+id/channel_slide_thumbnail_bg"
    android:layout_width="134dp"
    android:layout_height="134dp"
    android:clickable="false"
    android:background="@drawable/thumb_fpo_223x223" />

<ImageView
    android:id="@+id/channel_slide_thumbnail_photo"
    android:layout_width="132dp"
    android:layout_height="132dp"
    android:layout_alignLeft="@+id/channel_slide_thumbnail_bg"
    android:layout_alignTop="@+id/channel_slide_thumbnail_bg"
    android:layout_marginLeft="1dp"
    android:layout_marginTop="1dp"
    android:adjustViewBounds="true" 
    android:scaleType="fitCenter"/>

<ImageView
    android:id="@+id/channel_slide_thumbnail_header"
    android:layout_width="134dp"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/channel_slide_thumbnail_bg"
    android:layout_alignTop="@+id/channel_slide_thumbnail_bg"        
    android:background="@drawable/header_thumb_channel" />

<TextView 
    android:id="@+id/channel_slide_thumbnail_channel_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/channel_slide_thumbnail_header"
    android:layout_alignLeft="@+id/channel_slide_thumbnail_header"
    android:layout_marginLeft="6dp"
    android:textSize="12sp"
    android:textColor="@color/white"/>

<TextView 
    android:id="@+id/channel_slide_thumbnail_viewer_number"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/channel_slide_thumbnail_header"
    android:layout_alignRight="@+id/channel_slide_thumbnail_header"
    android:layout_marginRight="6dp"
    android:textSize="12sp"/>

HVLV's container

<RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content">       

    <ImageView 
        android:id="@+id/slide_menus_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/back_home" />

    <ImageView 
        android:id="@+id/slide_menus_recommended_subheader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/subheader_channels" />

    <TextView 
        android:id="@+id/slide_menus_recommended_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/slide_menus_recommended_subheader"
        android:layout_marginLeft="@dimen/slider_subheader_horizontal_margin"
        android:layout_marginBottom="@dimen/slider_subheader_vertical_margin"
        android:text="@string/recommended_label" />

    <it.sephiroth.android.library.widget.HorizontalVariableListView
        android:id="@+id/slide_menus_recommended_slider"
        android:layout_width="fill_parent"
        android:layout_height="134dp"
        android:layout_below="@+id/slide_menus_recommended_subheader" />

    <ImageView 
        android:id="@+id/slide_menus_talk_subheader"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/slide_menus_recommended_slider"
        android:background="@drawable/subheader_channels" />

    <TextView 
        android:id="@+id/slide_menus_talk_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/slide_menus_talk_subheader"
        android:layout_marginLeft="@dimen/slider_subheader_horizontal_margin"
        android:layout_marginBottom="@dimen/slider_subheader_vertical_margin"
        android:text="@string/talk_label" />

    <it.sephiroth.android.library.widget.HorizontalVariableListView
        android:id="@+id/slide_menus_talk_slider"
        android:layout_width="fill_parent"
        android:layout_height="134dp"
        android:layout_below="@+id/slide_menus_talk_subheader" />

</RelativeLayout>

Element adapter

public class ChannelSlideThumbnailsAdapter extends BaseAdapter {

private Activity activity;
private List<ChannelSlideData> channelsSlideData;
private static LayoutInflater inflater=null;

public ChannelSlideThumbnailsAdapter(Activity a, List<ChannelSlideData> channelsSlideData) {
    activity = a;
    this.channelsSlideData = channelsSlideData;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

public int getCount() {
    return channelsSlideData.size();
}

public Object getItem(int position) {
    return position;
}

public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

    View vi = convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.view_channelslidethumbnail, null);

    ImageView channelPhoto = (ImageView) vi.findViewById(R.id.channel_slide_thumbnail_photo);
    TextView channelName = (TextView)vi.findViewById(R.id.channel_slide_thumbnail_channel_name);
    TextView channelViewersNumber = (TextView)vi.findViewById(R.id.channel_slide_thumbnail_viewer_number);

    ChannelSlideData channelSlideData = channelsSlideData.get(position);

    // load image
    try {
        // get input stream
        InputStream ims = activity.getAssets().open(channelSlideData.avatarUrl);
        // load image as Drawable
        Drawable d = Drawable.createFromStream(ims, null);
        // set image to ImageView
        channelPhoto.setImageDrawable(d);            
    }
    catch(IOException ex) {
        // TODO - what should be done here?
    }

    channelName.setText(channelSlideData.channelName);
    channelViewersNumber.setText(Integer.toString(channelSlideData.viewersNo));

    return vi;
}

}


View creation:

mRecommendedSlide = (HorizontalVariableListView) getActivity().findViewById(R.id.slide_menus_recommended_slider);

    final List<ChannelSlideData> channelSlideThumbnailsData = new ArrayList<ChannelSlideData>();
    ChannelSlideData channelSlideData;

    for (int i=0; i < 10 ; i++) {
        channelSlideData = new ChannelSlideData();      
        channelSlideData.avatarUrl = "images/camel.png";
        channelSlideData.channelName = "Shows";
        channelSlideData.viewersNo = 1000;
        channelSlideThumbnailsData.add(channelSlideData);
    }

    ChannelSlideThumbnailsAdapter adapter = new ChannelSlideThumbnailsAdapter(getActivity(), channelSlideThumbnailsData);
    mRecommendedSlide.setOverScrollMode( HorizontalVariableListView.OVER_SCROLL_ALWAYS );
    mRecommendedSlide.setAdapter(adapter);

    // Click event for single list row
    mRecommendedSlide.setOnItemClickedListener( new OnItemClickedListener() {

        @Override
        public boolean onItemClick( AdapterView<?> parent, View view, int position, long id ) {
            Log.e( TAG_LOG, "onItemClick: " + position );
            return true;
        }
    });

Would appreciate any help with this.

Thanks,
K

I am supporting clicking on part of item, to do that I pass clickListener in adapter constructor and attach it in getView to proper view parts. It works.

To me it doesn't. I have used it precisely the same way as in the example, with the click listener attached to the HVLV, but nothing happens. The same with the selection listener.

Actually, there are two separate problems i am suffering from:

  1. Clicks are catched on the items of the horizontal view are not caught at all. (as i already described, and which i think is identical to the issue #17)
  2. The horizontal views are in a vertical ListView. In addition to the HVLV not catching any click events, it also doesnt allow vertical scrolling when the drag starts in an area in the HVLV. If i drag from other elements outside the HVLV, the vertical scroll works properly.

Tried to change the ListView to a custom one, overriding onInterceptTouchEvent, but it doesn't seem to work the magic.

Any ideas anyone?

I don't understand sentence "Clicks are catched on the items of the horizontal view are not caught at all."

" The horizontal views are in a vertical ListView. " - then take them out of this ListView and see if it helps.

"I have used it precisely the same way as in the example" - but I haven't. I told you that I used something like:

    HorizontalVariableListView hvlvList = (HorizontalVariableListView) view.findViewById( R.id.hvlvList );
    HorizontalAdapter listAdapter = new HorizontalAdapter(activity, list, clickListener, favoriteClickListener, this);
    hvlvList.setLayoutParams(params);
    hvlvList.setOverScrollMode( HorizontalVariableListView.OVER_SCROLL_ALWAYS );
    hvlvList.setEdgeGravityY( Gravity.CENTER );
    hvlvList.setAdapter( listAdapter );

And example has worked for me, so maybe start modifying example and see which steps makes click handler not to work. - typical debugging approach

Malachiasz,

I've changed a bit the listeners inside the view, and now everything works perfectly. What i was trying to say was that i suspected that since click events were not caught by the view listeners, the entire touch event management of the horizontal list went off. Now that the views inside the horizontal list are catching these click events, it seems that all other touch events (drag, etc) are working properly.

Thanks so much for your help. Appreciate it.

K

I have the same problem, I can not find a solution, please help.

Bigli, did you find a solution for your problem?

klommenz, no.