JSON的抽屉菜单不显示项目

时间:2015-10-30 09:19:05

标签: java android json

    public static List<NavItem> configuration() {

            final List<NavItem> i = new ArrayList<NavItem>();

            //DONT MODIFY ABOVE THIS LINE
            AsyncHttpClient client = new AsyncHttpClient();
            RequestHandle items = client.get("myurl", new AsyncHttpResponseHandler() {

                            @Override
                            public void onStart() {
                                    // called before request is started
                            }

                            @Override
                            public void onSuccess(int statusCode, Header[] headers, byte[] response) {

                                    String result = new String(response);


                                    JSONObject obj = null;
                                    JSONArray arr = null;
                                    try {
                                            obj = new JSONObject(result);
                                            arr = obj.getJSONArray("items");
                                    } catch (JSONException e) {
                                            e.printStackTrace();
                                    }

                                    for (int s = 0; s < arr.length(); s++) {
                                            String pltitle = null;
                                            String plid = null;
                                            try {
                                                    pltitle = arr.getJSONObject(s).getJSONObject("snippet").getString("title");
                                                    plid = arr.getJSONObject(s).getString("id");

                                            } catch (JSONException e) {
                                                    e.printStackTrace();
                                            }
                                            i.add(new NavItem(pltitle, R.drawable.icon_play, NavItem.ITEM, VideosFragment.class, plid + ",channelid"));


                                    }
                            }
                            @Override
                            public void onFailure ( int statusCode, Header[] headers,
                                                    byte[] errorResponse, Throwable e){
                                    // called when response HTTP status is "4XX" (eg. 401, 403, 404)
                            }

                            @Override
                            public void onRetry ( int retryNo){
                                    // called when request is retried
                            }
                    }

            );

            i.add(new NavItem("Tüm Videolar", R.drawable.icon_star, NavItem.EXTRA, VideosFragment.class, "asf"));
            i.add(new NavItem("Facebook",R.drawable.icon_fb, NavItem.EXTRA, FacebookFragment.class, "asd"));
            i.add(new NavItem("Twitter",R.drawable.icon_tw, NavItem.EXTRA, TweetsFragment.class, "asd"));
            i.add(new NavItem("Favoriler", R.drawable.ic_action_favorite, NavItem.EXTRA, FavFragment.class, null));
            i.add(new NavItem("Oynatma Listeleri", NavItem.SECTION));



            //It's Suggested to not change the content below this line


   // i.add(new NavItem("Settings", R.drawable.ic_action_settings, NavItem.EXTRA, SettingsFragment.class, null)); */

            //DONT MODIFY BELOW THIS LINE

        return i;

    }

我的应用程序使用此config.java来构建抽屉菜单,它实际上是静态菜单,但我进行了一些自定义并使其从json获取数据,但是在数据显示后它没有显示在抽屉上但是当我触摸时数据出现在抽屉上的一个项目我觉得它自己刷新了如何在数据采取时自动刷新?

1 个答案:

答案 0 :(得分:0)

请注意,您从AsyncHttpClient获取抽屉数据。它将在稍后执行并调用onSuccess()。所以function configuration()只返回TümVideolar,Facebook,Twitter,Favoriler,Oynatma Listeleri。

为此,请在onSuccess()结束时调用菜单适配器的notifyDataSetChanged()。