因此,我的应用程序具有可以动态添加的微调器,并且它们是从Course
对象的庞大数组列表中填充的,例如
courseSpinner = rowView.findViewById(R.id.first_spinner);
ArrayAdapter<Course> adapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, courseList);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
courseSpinner.setAdapter(adapter);
parentLayout.addView(rowView, parentLayout.getChildCount() - 1);
allSpinners.add(courseSpinner); //this is an ArrayList of spinners that keeps track of how many spinners exist currently since like mentioned before they can be dynamically added or removed
我想从每个新生成的微调器中删除在按下按钮之后选择的值。按下按钮时,会将值保存到单独的哈希图中,并删除所有现有的微调器,但是我需要实现某种将被调用的更新方法,该方法将从courseList
中填充或减去值,微调器从中获取值。感谢您的帮助
答案 0 :(得分:2)
这是您的带有转接头和列表的微调器:
ArrayAdapter<String> arrayAdapter;
arrayAdapter= new ArrayAdapter<String>(this, R.layout.spinner_indication, yourList);
Spinner yourSpinner;
yourSpinner.setAdapter(arrayAdapter)
从旧列表创建的新列表将其设置为适配器,如下所示:
yourList = newGeneratedList ;
arrayAdapet.notifyDataSetChanged();