本文介绍了android:如何在recyclerview中重定向另一个活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerViewHolder> {
String [] name={ "Androidwarriors","Stackoverflow","Developer Android","AndroidHive","Slidenerd","TheNewBoston","Truiton","HmkCode","JavaTpoint","Javapeper"};
Context context; LayoutInflater inflater;
public Recy
clerAdapter(Context context) {
this.context=context;
inflater=LayoutInflater.from(context);
}
@Override
public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v=inflater.inflate(R.layout.item_list, parent, false);
RecyclerViewHolder viewHolder=new RecyclerViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
holder.tv1.setText(name[position]);
holder.imageView.setOnClickListener(clickListener);
holder.imageView.setTag(holder);
}
View.OnClickListener clickListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
RecyclerViewHolder vholder = (RecyclerViewHolder) v.getTag();
int position = vholder.getPosition();
final Intent intent = new Intent(this, priya.class);
}
};
}
推荐答案
检查以下代码而不是此传递上下文.
Check below codeInstead of this pass context.
public class RecyclerAdapter extends RecyclerView.Adapter {
String [] name={"Androidwarriors","Stackoverflow","Developer Android","AndroidHive","Slidenerd","TheNewBoston","Truiton","HmkCode","JavaTpoint","Javapeper"};
Context context;
LayoutInflater inflater;
public RecyclerAdapter(Context context)
{
this.context=context;
inflater=LayoutInflater.from(context);
}
@Override public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
View v=inflater.inflate(R.layout.item_list, parent, false);
RecyclerViewHolder viewHolder=new RecyclerViewHolder(v);
return viewHolder;
}
@Override
public void onBindViewHolder(RecyclerViewHolder holder, int position) {
holder.tv1.setText(name[position]);
holder.imageView.setOnClickListener(clickListener);
holder.imageView.setTag(holder);
}
View.OnClickListener clickListener=new View.OnClickListener() {
@Override
public void onClick(View v) {
RecyclerViewHolder vholder = (RecyclerViewHolder) v.getTag();
int position = vholder.getPosition();
final Intent intent = new Intent(context, priya.class);
context.startActivity(intent);
}
};
}
这篇关于android:如何在recyclerview中重定向另一个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!