- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我在 tablayout 中的 recyclerview 中有一个 cardview。我在适配器的卡片 View 上放置了一个 onClickListener,但它不起作用。我只想在点击卡片时启动 EquationsActivity。在使用卡片的 Listener 界面之前,我已经让这个工作了。但这不起作用,唯一的区别是在这种情况下,我的 recyclerview 在 tablayout 中。我不确定这是否会导致任何问题。
感谢您的任何建议!
我的 recyclerViewAdapter:
public class recylcerAdapter extends RecyclerView.Adapter<recylcerAdapter.ViewHolder> {
private ListView listView;
private String title;
private Cursor cursor;
private Context context;
private TextView textView;
private ImageView imageView;
private int[] imageIds;
private String[] nameArray;
public static class ViewHolder extends RecyclerView.ViewHolder{
//define the viewholder and store card views
//constructor
private TextView textView;
private ImageView imageView;
private CardView cardView;
public ViewHolder(CardView v){
super(v);
cardView = v;
}
}
public recylcerAdapter(Context context, String title, Cursor cursor, int[]imageIds, String[]nameArray){
this.cursor = cursor;
this.title = title;
this.context = context;
this.imageIds = imageIds;
this.nameArray = nameArray;
}
@Override
public recylcerAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType){
//create a new view
CardView cardView = (CardView) LayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_main, parent, false);
return new ViewHolder(cardView);
}
public void onBindViewHolder(ViewHolder holder, final int position){
//set the values inside the given view
CardView cardView = holder.cardView;
ImageView imageView = (ImageView) cardView.findViewById(R.id.list_icon);
Drawable drawable = cardView.getResources().getDrawable(imageIds[position]);
imageView.setImageDrawable(drawable);
imageView.setContentDescription(nameArray[position]);
TextView textView = (TextView) cardView.findViewById(R.id.card_text);
textView.setText(nameArray[position]);
cardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast toast = Toast.makeText(context, "worked", Toast.LENGTH_SHORT);
toast.show();
Intent intent = new Intent(context, EquationsActivity.class);
context.startActivity(intent);
}
});
}
@Override
public int getItemCount(){
//return number of items in the data set
return nameArray.length;
}
}
我的回收站布局:
<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/recycler"
android:scrollbars="vertical"
android:clickable="true"
android:foreground="?android:attr/selectableItemBackground"
>
</android.support.v7.widget.RecyclerView>
我的主要协调器和标签布局:
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<include
layout="@layout/tool_bar"
android:id="@+id/toolBar"
/>
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="fixed"
app:tabGravity="fill"
android:background="@color/colorPrimary"
/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:orientation="vertical"
android:id="@+id/pager"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:clickable="true"
/>
</android.support.design.widget.CoordinatorLayout>
最佳答案
尝试从 ViewPager 中删除 android:clickable="true"
,并将其添加到您希望可点击的卡片的 xml 中。
关于java - tablayout 中 cardview 的 onClickListener 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38904304/
今天有小伙伴给我留言问到,try{...}catch(){...}是什么意思?它用来干什么? 简单的说 他们是用来捕获异常的 下面我们通过一个例子来详细讲解下
我正在努力提高网站的可访问性,但我不知道如何在页脚中标记社交媒体链接列表。这些链接指向我在 facecook、twitter 等上的帐户。我不想用 role="navigation" 标记这些链接,因
说现在是 6 点,我有一个 Timer 并在 10 点安排了一个 TimerTask。之后,System DateTime 被其他服务(例如 ntp)调整为 9 点钟。我仍然希望我的 TimerTas
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
我就废话不多说了,大家还是直接看代码吧~ ? 1
Maven系列1 1.什么是Maven? Maven是一个项目管理工具,它包含了一个对象模型。一组标准集合,一个依赖管理系统。和用来运行定义在生命周期阶段中插件目标和逻辑。 核心功能 Mav
我是一名优秀的程序员,十分优秀!