Unable to create call adapter for class example.Simple

后端 未结 14 1200
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 23:14

I am using retrofit 2.0.0-beta1 with SimpleXml. I want the retrieve a Simple (XML) resource from a REST service. Marshalling/Unmarshalling the Simple object with SimpleXML w

14条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 23:44

    You can implement a Callback, get the Simple from onResponse function.

    public class MainActivity extends Activity implements Callback {
    
        protected void onCreate(Bundle savedInstanceState) {
            final Retrofit rest = new Retrofit.Builder()
                        .addConverterFactory(SimpleXmlConverterFactory.create())
                        .baseUrl(endpoint)
                        .build();
            SimpleService service = rest.create(SimpleService.class);
            Call call = service.getSimple("572642");
            //asynchronous call
            call.enqueue(this);
    
            return true;
        }
    
        @Override
        public void onResponse(Response response, Retrofit retrofit) {
           // response.body() has the return object(s)
        }
    
        @Override
        public void onFailure(Throwable t) {
            // do something
        }
    
    }
    

提交回复
热议问题