简体   繁体   English

单击导航抽屉菜单选项时,什么都没有显示?

[英]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.

相关问题 当我单击回收站视图中的项目时,我可以使用导航抽屉作为下拉菜单吗? - Can i use a navigation drawer as a dropdown menu when i click on an item in a recyclerview? 单击底部菜单时如何打开侧面导航抽屉? - How to open the side navigation drawer when click on bottom menu? 导航菜单中的菜单布局未显示在导航抽屉中 - menu layout for the navigation menu is not showing up in the navigation drawer 当我调用repaint()方法时,屏幕上没有任何显示 - Nothing shows up to the screen when I call the repaint() method 我在项目单击侦听器上的导航抽屉不起作用 - My Navigation Drawer on item click listener not worked 我无法访问抽屉式导航菜单片段 - I cannot access the navigation drawer menu fragments Android Studio-App Preview显示xml布局,但是当我在手机上运行App时,没有任何显示 - Android Studio - App Preview shows the xml layout but when I run the App on Phone nothing shows up 动态添加的菜单项在导航抽屉中单击时消失 - Dynamically added menu items disappear on click in Navigation Drawer 菜单项在导航抽屉中单击,目的在于承载片段的活动 - Menu item click in a navigation drawer intent to activity hosting a fragment 单击选项菜单时,折叠工具栏上的滚动错误 - Wrong scroll on collapsing toolbar when i click options menu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM