gpt4 book ai didi

android - 在 RecyclerView 中获取微调器选择的项目

转载 作者:搜寻专家 更新时间:2023-11-01 08:23:54 24 4
gpt4 key购买 nike

我在 RecyclerView 中添加了 Spinner ,当我试图获取微调器选择的项目数据时,它得到另一个/错误的位置数据,有人建议我改正从 Spinner onItemSelected

中选择的项目和位置

这是我的代码

@Override
public void onBindViewHolder(final QuestionHolder holder, final int position) {
if (position % 2 == 1)
holder.itemView.setBackgroundColor(Color.parseColor("#F8F8F8"));
adapter = new ArrayAdapter<Option>(binding.getRoot().getContext(),
R.layout.item_spinner, questionList.get(position).getOptions());
adapter.setDropDownViewResource(R.layout.item_spinner);
binding.optionSpinner.setAdapter(adapter);

binding.serialNo.setText((position + 1) + ".");
binding.setQuestion(questionList.get(position));
binding.executePendingBindings();
binding.optionSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(holder.itemView.getContext(), position+" : "+binding.optionSpinner.getSelectedItem().toString(), Toast.LENGTH_SHORT).show();
spinnerData.setSelectedData(position, binding.optionSpinner.getSelectedItem().toString());
}

@Override
public void onNothingSelected(AdapterView<?> parent) {

}
});

}

最佳答案

我想你必须试试这个

  showSpinnerList.setOnItemSelectedListener(new 
AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int
position, long id) {
// On selecting a spinner item

String item = parent.getItemAtPosition(position).toString();

}

@Override
public void onNothingSelected(AdapterView<?> parent) {
// todo for nothing selected
}
});

关于android - 在 RecyclerView 中获取微调器选择的项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47302634/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com