问题描述
在我正在工作的项目中,我得到了一堆带有问题"(子级)的项目"(父级).正如我必须在列表中显示的那样,我使用了RecyclerView来做到这一点.为此,我使用了BigNerdRanch库( https://github.com/bignerdranch/expandable-recycler-view )
In the project I'm working, I get a bunch of "Projects"(parent) with "Issues" (child). As I have to show it in a list, I used RecyclerView to do it. To achieve it I used BigNerdRanch library (https://github.com/bignerdranch/expandable-recycler-view)
问题来了,我需要单击孩子"以获取问题的所有信息并将其发送到另一活动.
The problem come's that I need to click on Child to take all the information of the issue and send it to another activity.
该库没有任何方法来处理子点击,因此我尝试实现一种解决方法并进行了工作(我认为还可以..),但是在这里我被阻止了.我不知道如何带这个被点击的孩子来启动带有必要信息的活动.
The library don't have any method to handle the child click, so I tried to implement a work around and worked (I think is ok..), but here I'm blocked. I don't know how to take the clicked child to launch the activity with the necessary info.
这是ProjectAdapter:
Here is the 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(子级):
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());
}
}
正如我说的那样,我对如何获取孩子的信息一无所知.
As I said,I'm stucked on How to get the child information.
我该如何解决?
推荐答案
@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
}
});
}
这篇关于展开式RecyclerView中的onClick(使用bignerdranch库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!