0
我試圖做一個RecyclerView
,其中每個recyclerItem
有3個單選按鈕。一旦我選擇了其中一個,我想獲得與單選按鈕選擇一致的對象。我的適配器在下面...當我點擊單選按鈕時,沒有任何反應。似乎永遠不會傳遞onCheckedChanged()方法...我做錯了什麼?我如何處理radioLike.OnCheckedChangeListener
?或者是方法onBindViewHolder
缺乏什麼?radiogroup處理回收站視圖適配器內部的單選按鈕選擇
public class LikeListAdapter extends RecyclerView.Adapter<LikeListAdapter.LikeItemViewHolder> {
private List<Goals> goalsList;
public LikeListAdapter(List<Goals> goalsList) {
this.goalsList = goalsList;
}
@Override
public LikeItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
Context context = parent.getContext();
LayoutInflater inflater = LayoutInflater.from(context);
View view = inflater.inflate(R.layout.recycler_item_like, parent, false);
return new LikeItemViewHolder(view);
}
@Override
public void onBindViewHolder(LikeItemViewHolder holder, int position) {
Goals goals = goalsList.get(position);
if (goals != null && getItemCount() > 0) {
holder.goalsDescriptionTextView.setText(goals.getDescription());
}
}
@Override
public int getItemCount() {
return goalsList.size();
}
public class LikeItemViewHolder extends RecyclerView.ViewHolder implements RadioGroup.OnCheckedChangeListener {
@Bind(R.id.description_goalsTextView)
TextView goalsDescriptionTextView;
@Bind(R.id.happy_radio)
RadioButton happyRadioButton;
@Bind(R.id.soso_radio)
RadioButton sosoRadioButton;
@Bind(R.id.angry_radio)
RadioButton angryRadioButton;
@Bind(R.id.radio_like)
RadioGroup radioLike;
public LikeItemViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
radioLike.setOnCheckedChangeListener(this); ???
}
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
Log.e("group","" + group);
Log.e("checkedId","" + checkedId);
switch (group.getId()) {
case (R.id.happy_radio):
Log.e("aqui", "happy");
break;
case (R.id.soso_radio):
Log.e("aqui", "soso");
break;
case (R.id.angry_radio):
Log.e("aqui", "angry");
break;
}
}
}
}
什麼問題?有錯誤嗎?如果是這樣,請編輯您的問題以包含錯誤或您期望的內容以及您所得到的內容。見[問]。 – 8bittree
對不起,我會盡量做得更清楚明確!這是我第一次在這裏編輯我的問題。請問你能幫幫我嗎? – Lili
正如您所料,'group.getId()'返回RadioGroup標識 – tachyonflux