0

我在 Android IDK 中创建了一个线程,为什么它说返回类型无效!我想要的只是显示jsonProfile 想要更改片段中的文本

Thread thread= new Thread(){
          if (getActivity()!=null)
          {
              getActivity().runOnUiThread(new Runnable() {
                  @Override
                  public void run() {
                      Profile profile = service.getProfile(text);
                      Gson gson = new Gson();
                      String json = gson.toJson(profile);
                      output.setText(json.toString());
                  }
              });
          }
      };
        thread.start();
4

1 回答 1

2

试试这个

    new AsyncTask<Void, Void, Void> (){
        private String json;

        protected Void doInBackground(Void... voids) {
            Profile profile = service.getProfile(text);
            Gson gson = new Gson();
            json = gson.toJson(profile);
            return null;
        }

        protected void onPostExecute(Void result) {
            output.setText(json);
        }
    }.execute();
于 2018-04-23T19:24:45.960 回答