单击导航抽屉菜单选项时没有显示任何内容?

时间:2015-07-20 10:28:46

标签: java android

我使用了json文件并显示它,但是当我点击导航抽屉菜单时,会打开一个空白页面,但不会显示任何内容。在同一个应用程序中,我使用了Json并显示了第二种情况的内容。但它对这个没有用。任何帮助都是适当的

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);
        }


    }


}

1 个答案:

答案 0 :(得分:0)

您是否尝试过添加function hehe { $a=@() $a+=2 $a+=4 $b=,$a write-verbose $b.count # if a variable is assigned ",$a", the value is always 1 return ,$a }

notifyDataSetChanged()

还要通过打印简单日志确保响应不为空。