2015-06-28 86 views
0

我建立了一个ListView,每次用户点击一个按钮时都会变得更大,我想限制用户,并且每天只允许4行。如何计算具有相同值的listview行数?

这就是为什么我要计算具有特定值(日期)的行数,并从当前创建的列表视图行中获取确切的值,以防止用户添加更多行。

我从Json的让我的数据:

try { 
        JSONObject jsonObj = new JSONObject(jsonStr); 

        // Getting JSON Array node 
        contacts = jsonObj.getJSONArray(TAG_CONTACTS); 

        // looping through All Contacts 
        for (int i = 0; i < contacts.length(); i++) { 
         JSONObject c = contacts.getJSONObject(i); 

         String id = c.getString(TAG_ID); 
         String date = c.getString(TAG_DATE); 

         HashMap < String, String > contact = new HashMap < String, String >(); 

         contact.put(TAG_ID, id); 
         contact.put(TAG_DATE, date); 
         contactList.add(contact); 

        } 
     } 
} 

谢谢。

回答

0

之前你的for循环,创建SimpleDateFormat的实例,取决于日期格式的JSON,例如:

SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/"); 

然后得到当前日期:

String currentDate = dateFormat.format(Calendar.getInstance().getTime()); 

再算上行当前的数日期内循环:

if (date.equals(currentDate)) { 
    count++; 
} 

退出循环后:

// number of rows user allowed to add today 
int allowed = LIMIT - count; 
相关问题