我需要帮助,我有这个代码。当我单击按钮时,它将搜索数组列表中的特定文本,然后将其填充到微调器中。同时,相同的微调文本行将分为4个文本视图。面临的问题是在选择按钮期间,更新了4个文本视图。但是当我选择下拉微调框列表并选择一个选项时,文本视图不会更新。我添加了吐司来检查选中的项目。当我选择列表时,toast弹出窗口显示正确的信息。只有文本视图不会更新。
@Override
protected void onCreate(Bundle savedInstanceState) {
.
.
.
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
titleString = spinner1.getItemAtPosition(i).toString();
String[] items = titleString.split(";");
for (String item : items)
{
Log.d("test", item);
contentData.add(item);
}
TextView titleText = (TextView) findViewById(R.id.titletextView);
titleText.setText(contentData.get(0));
TextView questionText = (TextView) findViewById(R.id.questiontextView);
questionText.setText(contentData.get(1));
TextView causeText = (TextView) findViewById(R.id.causetextView);
causeText.setText(contentData.get(2));
TextView solutionText = (TextView) findViewById(R.id.solutiontextView);
solutionText.setText(contentData.get(3));
Toast.makeText(MainActivity.this, "You Selected : " + foundList.get(i) + " Level ", Toast.LENGTH_SHORT).show();
}
按钮代码
public void buttonClicked(View v){
Log.d("test", "button clicked");
strFind2 = mainSearchView.getText().toString();
String strFind1 = "thr";
for (String str : list) {
if (str.contains(strFind2)) {
foundList.add(str);
Log.d("test", "contains search items");
spinner1 =(Spinner)findViewById(R.id.titleCategory1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, foundList);
spinner1.setAdapter(adapter);
} else {
Log.d("test", "don't contains search items");
}
}
}
答案 0 :(得分:0)
如果我理解了这个问题,您的问题可能是当您更改适配器后备阵列时,您需要告诉适配器数据已被更改。
按下按钮并更改foundList
后尝试此操作adapter.notifyDataSetChanged();