package com.example.admin.accountbook;
import android.annotation.TargetApi;
import android.icu.util.Calendar;
import android.os.Build;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class Dates extends AppCompatActivity {
ListView dates;
Date dte;
ArrayList dt9 = new ArrayList();
@TargetApi(Build.VERSION_CODES.N)
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dates);
dates = (ListView)findViewById(R.id.dates);
ArrayAdapter da =new ArrayAdapter
(this,R.layout.support_simple_spinner_dropdown_item,dt9);
dates.setAdapter(da);
Calendar calendar = Calendar.getInstance();
SimpleDateFormat formattedDate = new SimpleDateFormat("d/M/yyyy");
try {
for (int a = 1; a <= 31; a++)
{
calendar.add(Calendar.DATE, -1);
dte = calendar.getTime();
dt9.add(formattedDate.format(dte));
da.notifyDataSetChanged();
}
}catch(Exception e)
{
Log.e("output",e+"");
}
}
我到arraylist.But列表視圖不 返回那些dates.Listview填充獲取日期的名單隻有昨天的date.Getting在正確追溯到ArrayList中。請幫助 me.Thanks提前。錯誤添加ArrayList的項目的ListView
調用'da.notifyDataSetChanged() ;'出'for'循環。 – Piyush
我試過了,但沒有工作 – Devika