我一直在嘗試按照以下教程將選項(xiàng)菜單集成到我的列表視圖中:[ https://www.simplifiedcoding.net/create-options-menu-recyclerview-item-tutorial/]我已經(jīng)能夠讓菜單圖標(biāo)出現(xiàn)在列表視圖中的項(xiàng)目旁邊,但我無(wú)法點(diǎn)擊它來(lái)訪問(wèn)彈出菜單。我試圖在我的public void onBindViewHolder(MyViewHolder holder, int position)方法中實(shí)現(xiàn)這一點(diǎn)。我無(wú)法弄清楚為什么我無(wú)法執(zhí)行 onClick。我已經(jīng)發(fā)布了我的適配器代碼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); }
2 回答

白衣非少年
TA貢獻(xiàn)1155條經(jīng)驗(yàn) 獲得超0個(gè)贊
您在 上初始化了錯(cuò)誤的上下文public LeagueAdapter(Context context, List<League> leaguesList)
,從 更改 this.mCtx=mCtx
為this.mCtx = context
將解決問(wèn)題。
添加回答
舉報(bào)
0/150
提交
取消