Gán giá trị cho biến trong android java

Mình muốn lấy size trong biến notifyJsonArray gán vào biến countNotify thì có cách nào không ạ ?

public static List<Notification> bindNotifyData(JsonElement list)
    {
        List<Notification> results= new ArrayList<>();
        JsonObject dataJsonObj = list.getAsJsonObject();
        // get data api from Json array "updates"
        JsonArray notifyJsonArray = dataJsonObj.get("updates").getAsJsonArray();
        if(notifyJsonArray != null && notifyJsonArray.size() > 0) {
            for(int i = 0; i < notifyJsonArray.size(); i++) {
                JsonObject notifyJson = (JsonObject) notifyJsonArray.get(i);
                Notification notification = new Notification();
                notification.setContent(notifyJson.get("content").getAsString());
                // Convert timestamp to Datetime
                String timestamp= notifyJson.get("time").getAsString();
                notification.setTime(ConvertTimestamp(timestamp));
                results.add(notification);
                // count numbers of the post in the list json array.
            }
        }
        return results;
    }
    public static int countNotify;

M.n giúp mình với

countNotify = notifyJsonArray.size();
Easy

2 Likes

mình làm v rồi. nhưng khi ra hàm MainActivity khai báo lấy giá trị thì nó luôn trả về 0 . nhưng khi cho một số cố định thì nó lại get được

Thế thì phải xem lại code “đúng như thế chưa”

2 Likes
83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?