我在Android IDK中创建了一个线程,为什么它说无效的返回类型!我想要的是显示我从Profile
获得的json
我想更改片段中的文字
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();
尝试此
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();