czyw 2019-07-16 11:22 采纳率: 66.7%
浏览 403
已采纳

从服务器接收的json数据,gson解析生成bean对象,怎么让页面显示出来

1.我在mainactivity建了一个空的内部类

Response response = okHttpClient.newCall (request).execute ();
String date = response.body ().string ();
Gson gson = new Gson ();
  F_User f_user = gson.fromJson (date, F_User.class);
    ```
这样是不是就能创建,并且给F_User这个类的对象赋值


2.接着怎么显示在页面不知道咋做,

``` if (date != null) {
            Gson gson = new Gson ();
            F_User f_user = gson.fromJson (date, F_User.class);

        //把解析好的数据发送到页面
            TextView tv_id = findViewById (R.id.tv1);
            tv_id.setText(f_user.getF_id ());

            TextView tv_name = findViewById (R.id.tv2);
            tv_name.setText(f_user.getF_username ());
            TextView tv_group = findViewById (R.id.tv3);
            tv_group.setText(f_user.getF_group ());
            TextView tv_role = findViewById (R.id.tv4);
            tv_role.setText(f_user.getF_role ());
            TextView tv_role_index = findViewById (R.id.tv5);
            tv_role_index.setText(f_user.getF_role_index ());
            TextView tv_passcode = findViewById (R.id.tv6);
            tv_passcode.setText(f_user.getF_passcode ());
                        //加入message
                        Message message = new Message ();
            message.what =1;
            handler.sendMessage (message);

                        public Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1://_这个位置写的对吗_
                   *_ BaseAdapter adapter=new BaseAdapter () {
                    }
                            (this,R.layout.activity_main);

                    .setAdapter();
                    break_;*
            }

```是这个样子就可以了吗?
3.下面是我copy的模板地址
[引用地址](https://blog.csdn.net/qq_26650589/article/details/70256219 "A")


因为数据格式变了,导致项目解析数据之后的步骤不知道还需要不,想用ListView接,因为刚接触安卓,拖控件也拖不明白,辛苦大神们了。
  • 写回答

5条回答

  • Burcy Wen 2019-07-16 12:02
    关注

    这个就好比画图纸,有人来给你讲了这里面需要画什么,需要注意什么,什么逻辑,
    然后你会根据这些内容并将其呈现在图纸中。

    现在你已经做好了数据接收以及呈现的内容,name你需要去绘制需要呈现的ui界面,然后将这些数据填充到界面上各个控件里就好了,例如

    TextView tv_name = findViewById(R.id.tvame);
    tv_name.setText(f_user.name);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题