如何通过它的价值,而不是当前位置设置微调默认? [英] How to set Spinner Default by its Value instead of Postion?
问题描述
我有1-50记录在数据库中。我使用的游标,并设置这些值使用简单的游标适配器微调获取这些数据。现在,我需要的是我想设置一个值,说39的值作为默认值。但不是由它的位置,我想用它的值来设置。
I have 1-50 records in the database. I am fetching those data using cursor and set those values to Spinner using Simple Cursor Adapter. Now what i need is i want to set one value say 39th value as default. But not by its position i want to set by its value.
我知道如何通过它的位置设置微调默认
I know how to set the spinner default by its position
spinner.setSelection(39)
将设置微调器的值。
will set the spinner to that value.
但我确实没有关于它的数据库中的值(文本)设置微调默认的任何想法。 我知道在数据库中的值。对于如书是在微调的一个值。我需要设置微调默认的书籍。
But i didn't have any idea about setting the spinner default by its value(text) in the database. I know the values in the database. For eg "books" is one of the value in the spinner. I need to set the spinner default as books.
是否有任何可能的方式来做到这一点?
Is there any possible way to do this?
感谢您的帮助家伙...
Thanks for you help guys...
推荐答案
最后,我用下面的方法,其中微调的位置可以通过它的字符串得到解决的问题
Finally, i solved the problem by using following way, in which the position of the spinner can be get by its string
private int getPostiton(String locationid,Cursor cursor)
{
int i;
cursor.moveToFirst();
for(i=0;i< cursor.getCount()-1;i++)
{
String locationVal = cursor.getString(cursor.getColumnIndex(RoadMoveDataBase.LT_LOCATION));
if(locationVal.equals(locationid))
{
position = i+1;
break;
}
else
{
position = 0;
}
cursor.moveToNext();
}
调用方法
Spinner location2 = (Spinner)findViewById(R.id.spinner1);
int location2id = getPostiton(cursor.getString(3),cursor);
location2.setSelection(location2id);
我希望这将有助于为一些一..
I hope it will help for some one..
这篇关于如何通过它的价值,而不是当前位置设置微调默认?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!