gpt4 book ai didi

android - 显示在 recyclerview 中点击的项目的详细信息

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:07:40 24 4
gpt4 key购买 nike

我能够检测到单个回收站 View 项目的位置,并能够在点击时对其进行烘烤。现在我不想继续进行新 Activity 并显示所点击项目的详细信息,我该怎么做?比如说,我正在显示联系人姓名列表并点击我不想打开一个新 Activity 显示该联系人的详细信息......至少,我怎样才能在点击那个联系人项目时再次 toast 联系人姓名,点击时的当前变量如何对我可用?我计划 bundle 这些变量并发送它们并在那里显示。

我知道我必须在这里实现

public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {  
private OnItemClickListener mListener;

public interface OnItemClickListener {
public void onItemClick(View view, int position){
//i know i have to implement here

}


}

最佳答案

在我这样做之前,我遇到了同样的问题。

创建了一个客户 RecyclerListener:

public class RecyclerItemClickListener implements RecyclerView.OnItemTouchListener {
private OnItemClickListener mListener;

public interface OnItemClickListener {
public void onItemClick(View view, int position);
}

GestureDetector mGestureDetector;

public RecyclerItemClickListener(Context context, OnItemClickListener listener) {
mListener = listener;
mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
return true;
}
});
}

@Override
public boolean onInterceptTouchEvent(RecyclerView view, MotionEvent e) {
View childView = view.findChildViewUnder(e.getX(), e.getY());
if (childView != null && mListener != null && mGestureDetector.onTouchEvent(e)) {
mListener.onItemClick(childView, view.getChildAdapterPosition(childView));
}
return false;
}

@Override
public void onTouchEvent(RecyclerView view, MotionEvent motionEvent) {
}

@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

}
}

然后在 recyclerView 的 Activity 中:

private void registerCallClickBack() {

recyclerView.addOnItemTouchListener(new RecyclerItemClickListener(getActivity().getApplicationContext(), new RecyclerItemClickListener.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
Intent intent = new Intent(this, DetailActivity.class);
intent.putExtra("contact_name", customList.get(position).getName());
intent.putExtra("contact_image", customList.get(position).getImage());
intent.putExtra("contact_tel", customList.get(position).getMobile());
intent.putExtra("contact_email", customList.get(position).getEmail());
startActivity(intent);
}
}));
}

其中 customList 是我的联系人 ArrayList。

希望对你有帮助

关于android - 显示在 recyclerview 中点击的项目的详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33871703/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com