如何从数据库得到微调的值 [英] How to get the values from DB in spinner
本文介绍了如何从数据库得到微调的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取值进入从DB微调。我想从DB UI显示值或DATAS。难道光标必要使用填充值到UI?
How to get values into the spinner from the DB. I want to display values or datas on UI from DB. Is it cursor necessary to use to populate the values onto the UI?
推荐答案
我只是跟着事情,才能从数据库中,当值的微调值改变由现在的位置 -
I just follow the things to get the values from database, when the spinner values changed by postion -
Java类的
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;
}
只是做你需要这样的步骤。
Just do what you need like these steps.
这篇关于如何从数据库得到微调的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文