0

I have a ListView and every item in this listview contains a gridview and a header textview. Now I want to recognize when the user clicks anywhere on the whole item, so I tried to set an onItemClickListener. Unfortunately this doesn't seem to work because I didn't get the debug log I added to the click method.

My ListView looks like the following

<ListView
                android:id="@+id/listview_previous_issues"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:descendantFocusability="blocksDescendants"
                android:layout_marginBottom="@dimen/article_separator_margin_topbottom"
                android:divider="@null"
                android:dividerHeight="0dp" />

And the GridView of the list items are this:

<GridView 
android:id="@+id/read_news"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:numColumns="auto_fit"
android:columnWidth="@dimen/settings_and_issues_read_issues"
android:stretchMode="columnWidth"
android:verticalSpacing="@dimen/paddingSmall"
android:horizontalSpacing="@dimen/paddingSmall"
android:listSelector="#00000000"
android:focusable="false"
android:focusableInTouchMode="false"
android:clickable="false"/>

Update: The call of onItemClickListener

mIssueList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d("debug", "Klicke auf Ressort mit der Id " + pRessorts.get(position).mRessortId);

            //Setze die Ressort-ID welche Topnews angezeigt werden
            SharedPreferenceHelper.setLongForKey(Constants.PREFS_SHOWN_TOPNEWS_ID, pRessorts.get(position).mRessortId);

            //Refreshe die Ansicht
            mContext.refresh();

        }
    });

I think that the GridView is getting the click event instead of the listview, but I'm not sure if this is correct. Can anyone point out what I have to do to get my clickevents at the listview?

jennymo
  • 1,450
  • 1
  • 18
  • 43
  • can you able to post your onclick ? – Sree Aug 05 '15 at 10:54
  • http://stackoverflow.com/a/5726131 look this – Sree Aug 06 '15 at 05:04
  • Unfortunately not. This post is about how to implement a gridview into an listview. I have already done this and its working. I want to know how to retrieve the click event with my onItemClickListener, because the listview currently didn't get one. – jennymo Aug 06 '15 at 12:00

1 Answers1

0

So, I was able to solve the problem on my own. Maybe this is helpful for anyone:

I override the dispatchTouchEvent method of my custom gridview, so that it doesn't get the touch event

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    return false;
}

Additionally, instead of an onItemClickListener I set a simple ClickListener at each listitem in the getView method of my ListAdapter and it worked.

jennymo
  • 1,450
  • 1
  • 18
  • 43