【发布时间】:2017-11-21 16:40:55
【问题描述】:
我试图做到这一点,当我点击 RecyclerView 上的和项目时,它将打开新活动,其中包含所点击项目的详细信息。
我的adapter.java代码是:
public class AdapterUsersData extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private Context context;
private LayoutInflater inflater;
List<UsersData> data= Collections.emptyList();
UsersData current;
int currentPos=0;
// create constructor to innitilize context and data sent from MainActivity
public AdapterUsersData(Context context, List<UsersData> data){
this.context=context;
inflater= LayoutInflater.from(context);
this.data=data;
}
// Inflate the layout when viewholder created
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view=inflater.inflate(R.layout.container_users, parent,false);
MyHolder holder=new MyHolder(view);
return holder;
}
// Bind data
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
// Get current position of item in recyclerview to bind data and assign values from list
final MyHolder myHolder= (MyHolder) holder;
final UsersData current=data.get(position);
myHolder.textFirstName.setText("First Name: " + current.fname);
myHolder.textPassword.setText("Pass: " + current.password);
myHolder.textLastName.setText("Last Name: " + current.lname);
myHolder.textEmail.setText("Email. " + current.email);
}
// return total item from List
@Override
public int getItemCount() {
return data.size();
}
class MyHolder extends RecyclerView.ViewHolder{
TextView textFirstName;
TextView textPassword;
TextView textLastName;
TextView textEmail;
// create constructor to get widget reference
public MyHolder(View itemView) {
super(itemView);
textFirstName= (TextView) itemView.findViewById(R.id.textFirstName);
textPassword = (TextView) itemView.findViewById(R.id.textPassword);
textLastName = (TextView) itemView.findViewById(R.id.textLastName);
textEmail = (TextView) itemView.findViewById(R.id.textEmail);
}
}
}
例如,我想将“curremt.fname .......”解析为另一个活动,以向用户显示单击项目的完整详细信息。
【问题讨论】:
-
问题解决了吗?如果没有那么我会给一个适配器..
-
没有,还没解决
-
检查我的适配器。我认为它会起作用..但它与你有点不同..
-
你做到了吗……我想你做到了。
-
@O.Men 你的问题解决了吗?
标签: android android-recyclerview android-parser