在我工作的项目中,我得到了一堆"项目"(父母)与"问题" (儿童)。由于我必须在列表中显示它,我使用RecyclerView来完成它。为了实现它,我使用了BigNerdRanch库(https://github.com/bignerdranch/expandable-recycler-view)
问题是,我需要点击Child以获取问题的所有信息并将其发送到另一个活动。
图书馆没有任何方法可以处理儿童点击,所以我尝试实施一个工作并且工作(我认为没问题。),但是这里我被阻止了。我不知道如何让点击的孩子用必要的信息启动活动。
这是ProjectAdapter:
public class ProjectAdapter extends ExpandableRecyclerAdapter<ProjectViewHolder, IssueViewHolder> {
private LayoutInflater mInflator;
private Context appContext ;
public ProjectAdapter(Context context, @NonNull List<? extends ParentListItem> parentItemList) {
super(parentItemList);
this.mInflator = LayoutInflater.from(context);
this.appContext = context;
}
@Override
public ProjectViewHolder onCreateParentViewHolder(ViewGroup parentViewGroup) {
View projectView = mInflator.inflate(R.layout.jira_project, parentViewGroup, false);
return new ProjectViewHolder(projectView);
}
@Override
public IssueViewHolder onCreateChildViewHolder(ViewGroup childViewGroup) {
View issueView = mInflator.inflate(R.layout.jira_issue, childViewGroup, false);
return new IssueViewHolder(issueView,this.appContext);
}
@Override
public void onBindParentViewHolder(ProjectViewHolder projectViewHolder, int position, ParentListItem parentListItem) {
Project project = (Project) parentListItem;
projectViewHolder.bind(project);
}
@Override
public void onBindChildViewHolder(IssueViewHolder issueViewHolder, int position, Object childListItem) {
Issue issue = (Issue) childListItem;
issueViewHolder.bind(issue);
}
}
IssueViewHolder(Child):
public class IssueViewHolder extends ChildViewHolder{
private TextView mIssueTextView; // contendra de momento el "summary" del issue
private Context appContext;
public IssueViewHolder(View itemView, final Context appContext) {
super(itemView);
this.appContext = appContext;
this.mIssueTextView = (TextView) itemView.findViewById(R.id.jir_issue_name);
this.mIssueTextView.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Log.d("JIRA", "CLICk CHILD");
Toast.makeText(appContext, "CHILD #"+getAdapterPosition() +"\n CHILD##"+getPosition(), Toast.LENGTH_LONG).show();
}
});
}
public void bind(Issue issue){
mIssueTextView.setText(issue.getKey());
}
}
正如我所说,我一直在坚持如何获取儿童信息。
我该如何解决?
答案 0 :(得分:0)
@Override
public void onBindChildViewHolder(IssueViewHolder issueViewHolder, int position, Object childListItem) {
Issue issue = (Issue) childListItem;
issueViewHolder.bind(issue);
issueViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//your code
}
});
}