如何自动更新TexT? Android Studio?

时间:2016-01-29 16:50:17

标签: android textview refresh

我正在解析一个JSON响应,当我点击一个按钮时它会更新文本,但只有刷新时,如何立即获取它,并动态更新texT ??

clear;close all;
load Connect
imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
Array = zeros(6,7);
Player = 1;
Winner = 0;
row1 = 6;
row2 = 6;
row3 = 6;
row4 = 6;
row5 = 6;
row6 = 6;
row7 = 6;
while sum(sum(Array == 0)) > 0 && Player == 1
switch Player
   %%%%%%%% Player 1 %%%%%%%%%%
    case 1 
        choice = menu('Player 1: Choose a column','Col 1','Col 2','Col 3','Col 4','Col 5','Col 6','Col 7');
        switch choice 
            case 1 
                if(Array(row1,1))~=0
                   row1=row1-1;
                end
                if(row1 < 1)
                    error('Column is full. Choose a new column.');
                end
                Board{row1,1} = blackchip;
                imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                Array(row1,1) = 1;

            case 2
                if(Array(row2,2))~=0
                    row2= row2-1;
                end
                if(row2 < 1)
                    error('Column is full. Choose a new column.');
                end
                Board{row2,2} = blackchip;
                imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                Array(row2,2) = 1;

            case 3
                if(Array(row3,3))~=0
                    row3= row3-1;
                end
                if(row3 < 1)
                    error('Column is full. Choose a new column.');
                end
                Board{row3,3} = blackchip;
                imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                Array(row3,3) = 1;

            case 4
                if(Array(row4,4))~=0
                   row4= row4-1;
                end
                if(row4 < 1)
                    error('Column is full. Choose a new column.');
                end
                Board{row4,4} = blackchip;
                imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                Array(row4,4) = 1;

            case 5
                if(Array(row5,5))~=0
                    row5= row5-1;
                end
                if(row5 < 1)
                    error('Column is full. Choose a new column.');
                end
                Board{row5,5} = blackchip;
                imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                Array(row5,5) = 1;

            case 6
                if(Array(row6,6))~=0
                    row6 = row6-1;
                end
                if(row6 < 1)
                    error('Column is full. Choose a new column.');
                end
                Board{row6,6} = blackchip;
                imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                Array(row6,6) = 1;

            case 7
                if(Array(row7,7))~=0
                    row7= row7-1;
                end
                if(row7 < 1)
                    error('Column is full. Choose a new column.');
                end
                Board{row7,7} = blackchip;
                imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                Array(row7,7) = 1;
                check = 0;
                while check == 0
                      if(row7 < 1)
                         fprintf('Please select another column');
                         if(Array(row7,7))~=0
                              row7 = row7-1;
                         end
                            Board{row7,7} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row7,7) = -1;
                         else
                           check = 1;
                      end
                end
end

        %%%%%%%%%% Player 2 %%%%%%%%%%%
        Player = 2;
        while sum(sum(Array == 0)) > 0 && Player == 2
            switch Player
                 case 2 %Player 1
                    choice = menu('Player 2: Choose a column:','Col 1','Col 2','Col 3','Col 4','Col 5','Col 6','Col 7');
                    switch choice 
                        case 1
                            if(Array(row1,1))~=0
                                row1= row1-1;
                            end
                            if(row1 < 1)
                                error('Column is full. Choose a new column.');
                            end
                            Board{row1,1} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row1,1) = -1;

                        case 2
                            if(Array(row2,2))~=0
                                row2= row2-1;
                            end
                            if(row2 < 1)
                                error('Column is full. Choose a new column.');
                            end
                            Board{row2,2} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row2,2) = -1;

                        case 3
                            if(Array(row3,3))~=0
                              row3= row3-1;
                            end
                            if(row3 < 1)
                                error('Column is full. Choose a new column.');
                            end
                            Board{row3,3} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row3,3) = -1;

                        case 4
                            if(Array(row4,4))~=0
                                row4= row4-1;
                            end
                            if(row4 < 1)
                                error('Column is full. Choose a new column.');
                            end
                            Board{row4,4} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row4,4) = -1;

                        case 5
                            if(Array(row5,5))~=0
                                row5 = row5-1;
                            end
                            if(row5 < 1)
                                error('Column is full. Choose a new column.');
                            end
                            Board{row5,5} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row5,5) = -1;

                        case 6
                            if(Array(row6,6))~=0
                               row6 = row6-1;
                            end
                            if(row6 < 1)
                                error('Column is full. Choose a new column.');
                            end
                            Board{row6,6} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row6,6) = -1;

                        case 7
                            if(Array(row7,7))~=0
                               row7 = row7-1;
                            end
                            if(row7 < 1)
                                error('Column is full. Choose a new column.');
                            end
                            Board{row7,7} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row7,7) = -1;
                            check = 0;
                            while check == 0
                                if(row7 < 1)
                                    fprintf('Please select another column');
                                    if(Array(row7,7))~=0
                                        row7 = row7-1;
                                    end
                            Board{row7,7} = redchip;
                            imshow([Board{1,:};Board{2,:};Board{3,:};Board{4,:};Board{5,:};Board{6,:}])
                            Array(row7,7) = -1;
                                else
                                    check = 1;
                                end
                            end
                    end 
            end
            Player = 1;
        end
end
end

我唯一想过的就是在我的听众中回忆起jsonarray

JsonArrayRequest request = new JsonArrayRequest(Request.Method.GET, URL_ANSWER, (String) null, new Response.Listener<JSONArray>() {
            @Override
            public void onResponse(JSONArray response) {
                listblogs = parseJSONResponseQuestion(response);
                mAdapterQuestion.setBloglist(listblogs);
                System.out.println(response);
                System.out.println("it worked!!!");
            }

        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                System.out.println(error);

            }
        });
        mRequestQueue.add(request);
    }


    private ArrayList<Blogs> parseJSONResponseQuestion(JSONArray response) {
        if (!response.equals("")) {
            ArrayList<Blogs> blogsArrayList = new ArrayList<>();
            try {
                StringBuilder data = new StringBuilder();
        for (int i = 0; i < response.length(); i++) {
            JSONObject currentQuestions = response.getJSONObject(i);
            String text = currentQuestions.getString("text");
            String questionId = currentQuestions.getString("questionId");
            String votes = currentQuestions.getString("votes");
            String Answerid = currentQuestions.getString("id");
            String selectedId = currentQuestions.getString("selected");
            System.out.println(response.length() + "length");

            data.append(text + Answerid + "\n");

            System.out.println(data);
            Blogs blogs = new Blogs();
            blogs.setMtext(text);
            blogs.setVotes(votes);
            blogs.setId(Answerid);
            blogs.setSelected(selectedId);
            System.out.print(Answerid);
            listblogs.add(blogs);
        }
        System.out.println(data.toString());
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

return listblogs;
}

}

0 个答案:

没有答案