TonicArtos / StickyGridHeaders

This project has been superseded by SuperSLiM, a layout manager for RecyclerView. I strongly recommend using SuperSLiM and not StickyGridHeaders.
http://tonicartos.com
Apache License 2.0
1.47k stars 442 forks source link

Button in header when implementing StickyGridHeaders #98

Closed zsoflin closed 6 years ago

zsoflin commented 10 years ago

I am running into issues when trying to add a clicklistener to a clickable ImageView in the headerview. In getHeaderView() in my BaseAdapter I am trying to do the following:

getHeaderView

@Override
public View getHeaderView(final int pos, View view, ViewGroup viewGroup) {
    view = inflater.inflate(R.layout.gallery_item,viewGroup, false);
    TextView title = (TextView) view.findViewById(R.id.title);
    TextView date =  (TextView) view.findViewById(R.id.date);
    ImageView settings = (ImageView) view.findViewById(R.id.folder_settings);

    settings.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Toast.makeText(mContext, "The Click Worked.", Toast.LENGTH_SHORT).show();
        }

    });

    GalleryItem galleryItem = galleryItems.get(pos);

    icon.setImageResource(setIcon(galleryItem.getMode()));
    title.setText(galleryItem.getTitle());
    Date da = galleryItem.record.getDate("FILE_DATE");

    SimpleDateFormat dateFormat = new SimpleDateFormat("LLLL-dd-yyyy");
    String mDate = dateFormat.format(da);
    date.setText(mDate);

    return view;
}

gallery_item.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:clickable="true"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_height="55dp"
android:background="@color/lightgraymain"
android:id="@+id/linearLayout">

<ImageView
    android:layout_width="55dp"
    android:layout_height="match_parent"
    android:id="@+id/icon"
    android:src="@drawable/ic_gallery_mode_tag" />

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceMedium"
    android:text="521 North 7th Street, Lincoln, NE"
    android:id="@+id/title"
    android:textColor="@color/black"
    android:layout_weight="1"
    android:gravity="center_vertical"
    android:layout_gravity="center_vertical"
    android:padding="5dp"
    android:fontFamily="sans-serif-condensed"
    android:enabled="true"
    android:ellipsize="marquee"
    android:textIsSelectable="false"
    android:singleLine="true"
    android:textSize="14dp"
    android:textStyle="bold" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:textAppearance="?android:attr/textAppearanceSmall"
    android:text="August-25-2014"
    android:id="@+id/date"
    android:layout_gravity="center_vertical"
    android:fontFamily="sans-serif-light"
    android:textColor="@color/gray" />

<ImageView
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:id="@+id/folder_settings"
    android:src="@drawable/ic_gallery_options"
    android:clickable="true"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:padding="10dp"
    android:layout_gravity="center"
    />

</LinearLayout>

I cannot get the toast to appear. I have tried implementing onHeaderClick() in the adapter as well to no avail. Any idea what is wrong?

yakubbaev commented 10 years ago

I have the same problem

R4md4c commented 9 years ago

Any updates on this problem ? I'm having the same problem too

tolbkni commented 9 years ago

This repository is now deprecated and will no longer see any development.

R4md4c commented 9 years ago

For anyone who was searching for a solution, I've copied the library code, and made the onHeaderClick listener to send the MotionEvent parameter and then did a view.onTouchEvent(ev); and it worked ! I know that this is a dirty and hacky solution but it did the job.