我正在使用Recycleview在Horizontal RecyclerView中显示联系人图像和姓名,并且可以正常加载。我已经实现了Click侦听器,该侦听器在单击时会打开新活动并根据RecyclerView的位置向用户显示详细信息。
但是我希望对RecyclerView进行自动滚动,以便每5秒钟recycleview自动滚动一次,我实现了以下代码,效果很好。
top.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
int lastItem = llm.findLastCompletelyVisibleItemPosition();
if(lastItem == llm.getItemCount()-1){
mHandler.removeCallbacks(SCROLLING_RUNNABLE);
Handler postHandler = new Handler();
postHandler.postDelayed(new Runnable() {
@Override
public void run() {
top.setAdapter(null);
top.setAdapter(staggeredBooksAdapter);
mHandler.postDelayed(SCROLLING_RUNNABLE, 5000);
}
}, 5000);
}
}
});
mHandler.postDelayed(SCROLLING_RUNNABLE, 5000);
但是现在,当我单击任何联系人时,将不会像以前那样启动带有用户详细信息的新活动。但是,当我删除滚动侦听器时,我可以再次单击RecyclerView项。
我的RecyclerView是
final LinearLayoutManager llm = new LinearLayoutManager(getActivity(),LinearLayoutManager.HORIZONTAL,false);
top.setLayoutManager(llm);
top.setHasFixedSize(true);
staggeredBooksAdapter = new TopAdapter(this, bookslist);
top.setAdapter(staggeredBooksAdapter);
并且来自适配器类是
@Override
public void onBindViewHolder(final MyViewHolder holder, final int position) {
database = FirebaseDatabase.getInstance();
g = bookslist.get(position);
holder.teacher_location.setText(g.getBlocas());
holder.teacher_name.setText(g.getSellername());
holder.profile_details.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
g = bookslist.get(position);
Intent intent = new Intent(v.getContext(), gender_details.class);
intent.putExtra(KEY_IMAGE, g.getPics());
v.getContext().startActivity(intent);
}
});
我该如何解决。。谢谢。
答案 0 :(得分:0)
将this类添加到您的项目中,然后添加以下代码:
recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(
this, top, new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Log.i("recyclerView ", "onItemClick " + position);
}
@Override
public void onLongItemClick(View view, int position) {
Log.i("recyclerView ", "onLongItemClick " + position);
}
}));
让我知道它是否有效。