Android 如何在spinner中从DB中获取值
如何从DB将值输入微调器。我想在DB的UI上显示值或数据。是否需要使用光标将值填充到UI上Android 如何在spinner中从DB中获取值,android,sqlite,Android,Sqlite,如何从DB将值输入微调器。我想在DB的UI上显示值或数据。是否需要使用光标将值填充到UI上 遵循它,非常简单。是的,需要光标来获取结果集对象或数据作为结果集。你可以从中找到解决方案 当微调器的值因位置而改变时,我只是按照这些操作从数据库中获取值- Java类 只需执行以下步骤即可。我使用的是“((微调器)findViewById(R.id.state)).setSelection(stateItems.getPosition(c.getString(c.getColumnIndexOrThro
遵循它,非常简单。是的,需要光标来获取结果集对象或数据作为结果集。你可以从中找到解决方案
当微调器的值因位置而改变时,我只是按照这些操作从数据库中获取值- Java类 只需执行以下步骤即可。我使用的是“((微调器)findViewById(R.id.state)).setSelection(stateItems.getPosition(c.getString(c.getColumnIndexOrThrow(StateDb.KEY\u state)));”但无法在spinner plz中加载数据,请以其他方式通知我。非常感谢。
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
//set some adapter here
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
public class MyOnItemSelectedListener implements OnItemSelectedListener
{
@SuppressWarnings("unused")
public void onItemSelected(AdapterView<?> parent,View view, int pos, long id)
{
try
{
switch(parent.getId())
{
case R.id.spinner2:
int selected_spinner_item_position=pos;
String expired_spinner_item =parent.getItemAtPosition(pos).toString();
if(selected_spinner_item_position==0)
{
//am just using simple cursor adapter here and getting the values from database using dh.fetchAll() when the position is 0
sc_adapter(dh.fetchAll());
spinnertemp = selected_spinner_item_position;
}
}
}
}
}
public Cursor fetchAll()
{
SQLiteDatabase db = this.getReadableDatabase();
cursor = db.query(t1, new String[] {"_id",task, pname, prior, time, dateformat, duptitle,dupname}, "stat=0", null, null, null, prior);
return cursor;
}