我一直在尝试按照以下教程将选项菜单集成到我的列表视图中:
[ https://www.simplifiedcoding.net/create-options-menu-recyclerview-item-tutorial/]
我已经能够让菜单图标出现在列表视图中的项目旁边,但我无法点击它来访问弹出菜单。我试图在我的public void onBindViewHolder(MyViewHolder holder, int position)方法中实现这一点。
我无法弄清楚为什么我无法执行 onClick。我已经发布了我的适配器代码
public class LeagueAdapter extends RecyclerView.Adapter<LeagueAdapter.MyViewHolder> {
private Context context;
private List<League> leaguesList;
public TextView buttonViewOption;
public void notifyDatasetChanged(List<League> newleagueslist) {
leaguesList.clear();
leaguesList.addAll(newleagueslist);
super.notifyDataSetChanged();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView name;
public TextView basescore;
public TextView basescorepercentage;
private TextView leagueAverage;
public TextView id;
public TextView timestamp;
public TextView buttonViewOption;
public MyViewHolder(View view) {
super(view);
id = view.findViewById( R.id.tvLeagueId);
name = view.findViewById(R.id.tvSeriesName );
basescore = view.findViewById(R.id.tvBaseScore );
basescorepercentage = view.findViewById(R.id.tvBaseScorePercentage );
leagueAverage = view.findViewById(R.id.tvLeagueAverage);
timestamp = view.findViewById(R.id.timestamp);
buttonViewOption = (TextView) itemView.findViewById(R.id.textViewOptions);
}
}
public LeagueAdapter(Context context, List<League> leaguesList) {
this.context = context;
this.leaguesList = leaguesList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.listview_league, parent, false);
return new MyViewHolder(itemView);
}
白衣非少年
相关分类