我正在尝试使用粘性网格标题 https://github.com/TonicArtos/StickyGridHeaders在我的 Android 应用程序中,它工作得很好,除非我尝试将点击监听器添加到 headerview 中的可点击 ImageView 中。在getHeaderView()
in my BaseAdapter
我正在尝试执行以下操作:
获取标题视图
@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>
我无法让吐司出现。我尝试过实施onHeaderClick()
在适配器中也无济于事。任何帮助将不胜感激。
谢谢你,
-扎克
您应该在托管 StickyGrid 的片段/活动中实现侦听器
我让它像这样工作:
@Override
public void onHeaderClick(AdapterView<?> adapterView, View view, long l) {
view.findViewById(R.id.folder_settings).performClick();
}
对于只有一个可点击元素的标题来说这是可以的。如果标题有多个可点击的元素,则此解决方案将不起作用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)