由网友(别惹我我是男神)分享简介:我一直在货架我的大脑试图得到这个工作。我想动态多年来从1900年进入到本年度变成微调。我不认为这是可能的使用XML定义的数组做的,但我可以做一个数组适配器?这是我到目前为止有:I have been racking my brain trying to get this to work. I want to dyna...
我一直在货架我的大脑试图得到这个工作。我想动态多年来从1900年进入到本年度变成微调。我不认为这是可能的使用XML定义的数组做的,但我可以做一个数组适配器?这是我到目前为止有:
I have been racking my brain trying to get this to work. I want to dynamically enter in years from 1900 to the current year into a spinner. I don't think that this is possible to do using an XML defined array but can I do it with an array adapter? Here is what I have so far:
ArrayList<String> years = new ArrayList<String>();
int thisYear = Calendar.getInstance().get(Calendar.YEAR);
for (int i = 1900; i <= thisYear; i++)
{
years.add(i);
}
adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, years);
//spinner to enter this list to
spinYear = (Spinner)findViewById(R.id.yearspin);
下面是XML的微调:
Here's the XML for the spinner:
<Spinner
android:id="@+id/yearspin"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
感谢您的帮助。
Thanks for any help.
推荐答案
您是非常密切的。试试这个:
You're very close. Try this:
ArrayList<String> years = new ArrayList<String>();
int thisYear = Calendar.getInstance().get(Calendar.YEAR);
for (int i = 1900; i <= thisYear; i++) {
years.add(Integer.toString(i));
}
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, years);
Spinner spinYear = (Spinner)findViewById(R.id.yearspin);
spinYear.setAdapter(adapter);
您刚才忘了补充
spinYear.setAdapter(adapter);
相关推荐
最新文章