美文网首页
Android RecyclerView Item 点击事件,简

Android RecyclerView Item 点击事件,简

作者: 笔迹i | 来源:发表于2017-05-26 09:09 被阅读0次

在适配器中设置项的点击事件即可,如需跳转Activity,则需要intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);


@Override

publicViewHolder onCreateViewHolder(ViewGroup parent,final intviewType) {

itemView= LayoutInflater.from(parent.getContext())

.inflate(R.layout.recyclerview_item,parent,false);

BBX_Adapter.ViewHolder viewHolder =newBBX_Adapter.ViewHolder(itemView);

returnviewHolder;

}

@Override

public voidonBindViewHolder(ViewHolder holder,final intposition) {

BBX bbx=list.get(position);

itemView.setOnClickListener(newView.OnClickListener() {

@Override

public voidonClick(View view) {

switch(position){

case6:

Intent intent=newIntent(MyApplication.getContext(), family_Activity.class);

intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);

MyApplication.getContext().startActivity(intent);

break;

case0:

Toast.makeText(MyApplication.getContext(),"nnnn", Toast.LENGTH_SHORT).show();

break;

}

}

});

holder.imageView.setImageDrawable(getBBXIcon(bbx.getIcon()));

holder.textView.setText(bbx.getUsername());

}

相关文章

网友评论

      本文标题:Android RecyclerView Item 点击事件,简

      本文链接:https://www.haomeiwen.com/subject/bfutfxtx.html