【发布时间】:2010-02-06 22:56:26
【问题描述】:
真的只是一个小问题,我想将当前年份放在我的应用程序的页脚中。每个页脚都是一个 TextView,可以在菜单屏幕等上看到。有没有办法在其中动态插入年份?
干杯, 劳伦斯
【问题讨论】:
真的只是一个小问题,我想将当前年份放在我的应用程序的页脚中。每个页脚都是一个 TextView,可以在菜单屏幕等上看到。有没有办法在其中动态插入年份?
干杯, 劳伦斯
【问题讨论】:
你可以这样做:
Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
TextView footer = findViewById(R.id.footer);
footer.setText("" + year);
【讨论】:
Hi Guys this is the code by what you can achieve the dropdown array of last 15 years (As the vehicle registration is valid for 15 years in India). So you can show this by the below code on Spinner dropdown in android.
ArrayList<YearModel> arrayListYear=new ArrayList<>();
int year,startYear,endYear;
Calendar calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
startYear=year-15;
endYear=startYear+14;
arrayListYear.clear();
for(int i=startYear;i<=endYear;i++){
arrayListYear.add(new YearModel(""+i));
}
ArrayList<String> names = new ArrayList<>();
for(YearModel model : arrayListYear) {
names.add(model.getName());
Log.e("Year","==>"+names);
}
spCarBuyYear.setAdapter(new ArrayAdapter<String>(MotorInsuranceActivity.this, R.layout.spinner_item, names));
【讨论】: