当前位置: 动力学知识库 > 问答 > 编程问答 >

java - Drawer Menu from JSON not showing items

问题描述:

 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;

}

My app uses this config.java to build drawer menu its actually static menu but I make some customizations and make it take data from json but after it takes data its not showing on drawer but when I'm touch an item on drawer the data appears I think its refreshing it self how can I make it auto refresh when data took?

网友答案:

Please note that you get drawer data form an AsyncHttpClient. It will execute and call onSuccess() later. So function configuration() only return Tüm Videolar, Facebook, Twitter, Favoriler, Oynatma Listeleri.

For this, please call notifyDataSetChanged() of your menu adapter at the end of onSuccess().

分享给朋友:
您可能感兴趣的文章:
随机阅读: