开发者

Inserting the current year into a TextView

Just a small problem really, I want to place the current year into the footer of my apps. Each footer is a TextView, which is seen on menu screens etc. Is there a w开发者_StackOverflow中文版ay to insert the year into this dynamically?

Cheers, Laurence


You can do something like:

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));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜