Android 使用SQLite数据库更新Spinner

Android 使用SQLite数据库更新Spinner,android,Android,添加显示的数据后,我需要不断更新微调器。 我的部分代码: public class MainActivity extends AppCompatActivity { ArrayAdapter<String> adapter; Spinner spinner; protected void onCreate(Bundle savedInstanceState) { ArrayList<String> categories = databaseHelper.ge

添加显示的数据后,我需要不断更新微调器。
我的部分代码:

public class MainActivity extends AppCompatActivity {  
ArrayAdapter<String> adapter;  
Spinner spinner;  

protected void onCreate(Bundle savedInstanceState) {
ArrayList<String> categories = databaseHelper.getAllCategories();
spinner = (Spinner) findViewById(R.id.spinner);
adapter =  new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, categories);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
公共类MainActivity扩展了AppCompatActivity{
阵列适配器;
纺纱机;
创建时受保护的void(Bundle savedInstanceState){
ArrayList categories=databaseHelper.getAllCategories();
微调器=(微调器)findViewById(R.id.spinner);
adapter=new ArrayAdapter(这是android.R.layout.simple\u微调器\u下拉菜单\u项,类别);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
旋转器。设置适配器(适配器);
}
在DatabaseHelper类中,我进行简单的查询,选择一列。

公共类MainActivity扩展了AppCompatActivity{
public class MainActivity extends AppCompatActivity {  
ArrayAdapter<String> adapter;  
Spinner spinner;
ArrayList<String> categories;  

protected void onCreate(Bundle savedInstanceState) {
categories = databaseHelper.getAllCategories();
spinner = (Spinner) findViewById(R.id.spinner);
adapter =  new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, categories);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}

private function updateSpinner(){
    categories.clear();
    categories.addAll(databaseHelper.getAllCategories());
    adapter.notifyDataSetChanged();
}
阵列适配器; 纺纱机; 阵列列表类别; 创建时受保护的void(Bundle savedInstanceState){ categories=databaseHelper.getAllCategories(); 微调器=(微调器)findViewById(R.id.spinner); adapter=new ArrayAdapter(这是android.R.layout.simple\u微调器\u下拉菜单\u项,类别); setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项); 旋转器。设置适配器(适配器); } 私有函数updateSpiner(){ 类别。清除(); categories.addAll(databaseHelper.getAllCategories()); adapter.notifyDataSetChanged(); }
公共类MainActivity扩展了AppCompatActivity{
阵列适配器;
纺纱机;
阵列列表类别;
创建时受保护的void(Bundle savedInstanceState){
categories=databaseHelper.getAllCategories();
微调器=(微调器)findViewById(R.id.spinner);
adapter=new ArrayAdapter(这是android.R.layout.simple\u微调器\u下拉菜单\u项,类别);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
旋转器。设置适配器(适配器);
}
私有函数updateSpiner(){
类别。清除();
categories.addAll(databaseHelper.getAllCategories());
adapter.notifyDataSetChanged();
}

谢谢你,兄弟!:)你应该调用该方法吗?和
类别。添加
可以替换为
适配器。添加所有
,列表作为parameter@Mariachi欢迎。请考虑@ CRKETETY0.7注释。代替循环,可以用<代码>适配器。Addia<代码>。我将更新答案,不要忘记接受。答案(勾号符号)。谢谢你,兄弟!:)你应该调用该方法吗?和
类别。添加
可以替换为
适配器。添加所有
,列表作为parameter@Mariachi欢迎。请考虑@ CRKETETY0.7注释。代替循环,可以用<代码>适配器。Addia<代码>。我将更新答案,不要忘记接受答案。(勾选符号)。