zoukankan      html  css  js  c++  java
  • 第二阶段冲刺九

    今天主要完成的任务:安卓端接收JSON数据,并构造适配器

    遇到的困难:JSON数据格式转化问题

    解决办法:引入阿里巴巴的json工具包即可

    源程序代码:

    LinearLayoutManager linearLayoutManager=new LinearLayoutManager(mContext);
            recyclerView.setLayoutManager(linearLayoutManager);
            String url = "http://39.101.190.190:8080/CloudNoteServlet/NoteServlet";
            OkHttpUtils
                    .get( )
                    .url(url)
                    .addParams("method", "getpublicNotes")
                    .build( )
                    .execute(new StringCallback( )
                    {
                        @Override
                        public void onError(Call call, Exception e, int id)
                        {
                            Toast.makeText(mContext,"网络异常", Toast.LENGTH_SHORT).show( );
                        }
    
                        @Override
                        public void onResponse(String response, int id)
                        {
                            JSONArray array = JSONArray.parseArray(response);
                            for (int i = 0; i < array.size( ); i++)
                            {
                                JSONObject json = array.getJSONObject(i);
                                Note_pojo notePojo = new Note_pojo();
                                notePojo.setNote_id(json.getInteger("note_id"));
                                notePojo.setUser_icon(json.getString("user_icon"));
                                notePojo.setUser_name(json.getString("username"));
                                notePojo.setTitle(json.getString("title"));
                                notePojo.setCourse(json.getString("course"));
                                notePojo.setDate(json.getString("date"));
                                notePojoList.add(notePojo);
                            }
                            if(flag)
                            {
                                publicNoteAdapter.refreshList();
                                swipeRefreshLayout.setRefreshing(false);//当刷新结束时隐藏刷新条
                            }
                            else
                            {
                                initView();
                            }
    
                        }
    
                    });
  • 相关阅读:
    MySQL行级锁、表级锁、页级锁详细介绍
    Spring REST是什么?(转)
    Spring REST(转)
    联系人项目
    三级联动(有刷新)
    Java中点击按钮返回上一页
    Java中隐藏显示效果
    理解RESTful架构(转)
    什么是REST?以及RESTful的实现(转)
    JSTL 核心标签库 使用(转)
  • 原文地址:https://www.cnblogs.com/weixiao1717/p/13085437.html
Copyright © 2011-2022 走看看