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 SQL Server下载
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥15 python爬取bilibili校园招聘网站
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件
  • ¥15 不同系统编译兼容问题
  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求