[英]Nothing shows up when i click my Navigation drawer menu options?
I have used json file and display it but when I click on navigation drawer menu a blank page opens but no content is displayed. 我已经使用了json文件并显示了它,但是当我单击导航抽屉菜单时,会打开一个空白页面,但是没有显示任何内容。 In the same application I have used Json and displayed the content for the second case.
在同一应用程序中,我使用了Json并显示了第二种情况的内容。 But it doesnt work for this one.
但这不适用于这个。 Any help would be appriciated
任何帮助都将被申请
public class NewNewsMain extends SherlockFragment {
private ListView listedView;
ArrayList<NewNews> newsList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.activity_newnews, container, false);
listedView = (ListView) rootView.findViewById(R.id.listed);
newsList= new ArrayList<>();
new NewsAsynctask().execute("http://www.thebritishcollege.edu.np/api/news");
return rootView;
}
public class NewsAsynctask extends AsyncTask<String,Void,Boolean> {
@Override
protected Boolean doInBackground(String... params) {
try {
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(params[0]);
HttpResponse response = client.execute(post);
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entities = response.getEntity();
String datas = EntityUtils.toString(entities);
JSONObject jObje = new JSONObject(datas);
JSONArray jArrays = jObje.getJSONArray("result");
for (int i = 0; i < jArrays.length(); i++) {
NewNews newss = new NewNews();
JSONObject jRealsobject = jArrays.getJSONObject(i);
newss.setTitle(jRealsobject.getString("title"));
// news.setThumbnail(jRealsobject.getString("thumbnail"));
newsList.add(newss);
}
return true;
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
@Override
protected void onPostExecute(Boolean result) {
super.onPostExecute(result);
if(result==true){
NewNewsAdapter adapters= new NewNewsAdapter(getActivity().getApplicationContext(), R.layout.newnews, newsList);
listedView.setAdapter(adapters);
}
}
}
Have you tried by adding notifyDataSetChanged()
? 您是否尝试过添加
notifyDataSetChanged()
?
NewNewsAdapter adapters = new NewNewsAdapter(getActivity().getApplicationContext(), R.layout.newnews, newsList);
listedView.setAdapter(adapters);
adapters.notifyDataSetChanged();
Also make sure the response is not null by printing a simple log. 还可以通过打印简单日志来确保响应不为空。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.