赞
踩
适配器是java类,不是Activity。
要手动获取上下文Context
- public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
- View view = LayoutInflater.from(parent.getContext())
- .inflate(R.layout.friend_user_item,parent,false);
- //编写点击事件
- final ViewHolder holder = new ViewHolder(view);
- holder.friendView.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- int position = holder.getAdapterPosition();
- FriendUser friendUser = mFriendUsers.get(position);
- Toast.makeText(v.getContext(),"点击了控件"+friendUser.getNumber(),
- Toast.LENGTH_SHORT).show();
- //用v.getContext();
- Intent intent = new Intent(v.getContext(), FriendInfoActivity.class);
- v.getContext().startActivity(intent);
- }
- });
- return holder;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。