我的 Iterator .remove() 有一个java.lang.UnsupportedOperationException
,但我相信这是考虑过的safe
,我认为我的代码实际上是“好的”,所以有人可以帮助我吗?
final List<String> liveList = Arrays.asList((String[]) button.getItems().toArray()); //create mutable List<String> from button.getItems() List<String>
final PremSpinner dropdown = new PremSpinner(this); //spinner (EG: "dropdown") of all the options
dropdown.setLayoutParams(col);
final ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, liveList); // <---+
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); // |
dropdown.setPadding(45, 15, 45, 15); // |
dropdown.setAdapter(dataAdapter); //the way you [populate] a `dropdown(spinner)` is via an `adapter` and a List<String> |
final EditText partSearcher = new EditText(this);
partSearcher.setLayoutParams(col);
partSearcher.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Log.w("typing",s.toString());
Iterator<String> iter = liveList.iterator();
while (iter.hasNext()) {
if (!iter.next().contains(s)) {
iter.remove(); //<--the UnsupportedOperationException is here
}
}
dataAdapter.notifyDataSetChanged();
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) {}
});
然后我将它们添加到table
tr = new TableRow(this);
tr.setLayoutParams(lp);
tr.addView(partSearcher);
table.addView(tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
tr = new TableRow(this);
tr.setLayoutParams(lp);
tr.addView(dropdown);
table.addView(tr, new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); //this makes it fat enough
该代码旨在为希望在其微调器中进行文本搜索的人移植,人们对动态微调器很感兴趣,但没有可靠的可行代码示例,所以我希望将这篇文章写成一篇博客文章,但我可以'想不通!