{"id":280279,"date":"2016-11-01T13:10:10","date_gmt":"2016-11-01T10:10:10","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=280279"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=280279","title":{"rendered":"\u0418\u0437\u0443\u0447\u0430\u0435\u043c Retrofit 2"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/b4b\/a01\/0c6\/b4ba010c6d5a4cb4856e76f6072ed89e.jpg\"\/><\/p>\n<p>  \u0412 \u043c\u0438\u0440\u0435 Android \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0435\u0442\u0438\u0449\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 <a href=\"http:\/\/square.github.io\">Square<\/a> \u2014 <a href=\"http:\/\/square.github.io\/retrofit\/\">Retrofit<\/a>. \u0427\u0442\u043e \u0436\u0435 \u044d\u0442\u043e \u0437\u0430 \u0437\u0432\u0435\u0440\u044c \u0442\u0430\u043a\u043e\u0439? Retrofit (\u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u0430\u0439\u0442\u0443) \u2014 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f Android \u0438 Java. \u0412 \u043c\u0438\u0440\u0435 \u0436\u0435 Android \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u2014 \u043d\u0435\u0437\u0430\u043c\u0435\u043d\u0438\u043c\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API. \u041a\u0430\u043a\u0438\u0445-\u0442\u043e \u043b\u0435\u0442 5 \u043d\u0430\u0437\u0430\u0434 Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0442\u044c\u044e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432\u043e\u0440\u043e\u0442\u0438\u0442\u044c \u0433\u043e\u0440\u044b \u043a\u043e\u0434\u0430 \u0441 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438, AsyncTask&#8217;\u0430\u043c\u0438 \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u00ab\u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c\u0438\u00bb \u0432\u0435\u0449\u0430\u043c\u0438. \u0418 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f Square \u0432\u044b\u043f\u0443\u0441\u0442\u0438\u043b\u0430 \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u2014 Retrofit.<\/p>\n<p>  \u0412 \u0441\u0435\u0442\u0438 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u043c\u043d\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0432\u043d\u044f\u0442\u043d\u044b\u0445 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u043e\u0432 \u043f\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0438\u0431\u0438\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u0439 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u044b \u0441 bash.im<br \/>  <a name=\"habracut\"><\/a>  <\/p>\n<h1>\u041b\u0443\u0447\u0448\u0435 \u043e\u0434\u0438\u043d \u0440\u0430\u0437 \u0443\u0432\u0438\u0434\u0435\u0442\u044c, \u0447\u0435\u043c \u0441\u0442\u043e \u0440\u0430\u0437 \u0443\u0441\u043b\u044b\u0448\u0430\u0442\u044c<\/h1>\n<p>  \u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435, \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0449\u0435\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e\u0442 API \u0441\u0430\u0439\u0442\u0430 <a href=\"http:\/\/www.umori.li\">Umorili<\/a>, \u0442\u0430\u043a \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u043d\u0438 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441 \u0431\u0430\u0448\u0430 \u0432 \u0443\u0434\u043e\u0431\u043d\u043e\u043c \u0434\u043b\u044f \u043f\u0430\u0440\u0441\u0438\u043d\u0433\u0430 \u0432\u0438\u0434\u0435. \u0412\u043e\u0442 \u0442\u0430\u043a \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/8fd\/9ca\/fcb\/8fd9cafcb14b434b9ec0b7bb70e29d26.png\" width=\"50%\"\/><i>\u0414\u0438\u0437\u0430\u0439\u043d\u043e\u043c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043d\u0435 \u0431\u043b\u0435\u0449\u0435\u0442<\/i><\/p>\n<p>  <s>\u041d\u0443 \u0447\u0442\u043e, \u0434\u0435\u0442\u0438, \u0432\u044b \u0433\u043e\u0442\u043e\u0432\u044b?<\/s>  <\/p>\n<h2>\u0417\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438<\/h2>\n<p>  \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 Retrofit \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0442\u0440\u0435\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438: Gradle, Maven, Jar. \u041e\u043f\u0438\u0448\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0439 \u0441\u043f\u043e\u0441\u043e\u0431.<\/p>\n<h3>Gradle<\/h3>\n<p>  \u0412 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0435 \u0441\u043b\u0443\u0447\u0430\u0435\u0432 \u0434\u043b\u044f \u0441\u0431\u043e\u0440\u043a\u0438 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u043f\u043e\u0434 Android \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443, \u0435\u0441\u043b\u0438 \u0432\u044b \u043d\u0435 \u0443\u0432\u0435\u0440\u0435\u043d\u044b, \u0431\u0435\u0440\u0438\u0442\u0435 \u044d\u0442\u043e\u0442 \u0432\u0430\u0440\u0438\u0430\u043d\u0442 \ud83d\ude42 (\u0437\u0434\u0435\u0441\u044c \u0438 \u0434\u0430\u043b\u0435\u0435 \u0434\u043b\u044f \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0431\u0443\u0434\u0443\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f Gradle)<br \/>  \u0414\u043b\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u0432 \u0444\u0430\u0439\u043b build.gradle \u043c\u043e\u0434\u0443\u043b\u044f \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0432 \u0440\u0430\u0437\u0434\u0435\u043b <code>dependencies<\/code> \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u0442\u0440\u043e\u0447\u043a\u0443  <\/p>\n<pre><code>compile 'com.squareup.retrofit2:retrofit:2.1.0'<\/code><\/pre>\n<p>  <\/p>\n<h3>Maven<\/h3>\n<p>  \u0415\u0441\u043b\u0438 \u043a\u0442\u043e-\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u044d\u0442\u0443 \u0441\u0438\u0441\u0442\u0435\u043c\u0443 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439 \u0438 \u0441\u0431\u043e\u0440\u043a\u0438, \u0442\u043e \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u0442\u0430\u043a  <\/p>\n<pre><code class=\"xml\">&lt;dependency&gt;   &lt;groupId&gt;com.squareup.retrofit2&lt;\/groupId&gt;   &lt;artifactId&gt;retrofit&lt;\/artifactId&gt;   &lt;version&gt;2.1.0&lt;\/version&gt; &lt;\/dependency&gt; <\/code><\/pre>\n<p>  <\/p>\n<h3>Jar<\/h3>\n<p>  \u041d\u0435 \u043f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u044d\u0442\u043e\u0433\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u0430, \u043d\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043b\u044e\u0431\u044f\u0442 \u0435\u0433\u043e.<br \/>  \u0421\u043a\u0430\u0447\u0438\u0432\u0430\u0435\u043c \u0441 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0430\u0439\u0442\u0430 jar \u0444\u0430\u0439\u043b (<a href=\"http:\/\/repo1.maven.org\/maven2\/com\/squareup\/retrofit2\/retrofit\/2.1.0\/retrofit-2.1.0.jar\">\u0441\u0441\u044b\u043b\u043a\u0430<\/a>) \u0438 \u043a\u0438\u0434\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043f\u0430\u043f\u043a\u0443 libs.<\/p>\n<p>  \u041f\u043e\u043c\u0438\u043c\u043e \u0441\u0430\u043c\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u043f\u0430\u0440\u0441\u0435\u0440 JSON \u0438 RecyclerView-v7, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0438\u0445  <\/p>\n<pre><code>compile 'com.squareup.retrofit2:converter-gson:2.1.0' \/\/\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440 JSON, \u043c\u043e\u0436\u043d\u043e, \u0435\u0441\u043b\u0438 \u043f\u0440\u0435\u0434\u043f\u043e\u0447\u0438\u0442\u0430\u0435\u0442\u0435, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c Jackson compile 'com.android.support:recyclerview-v7:25.0.0' \/\/RecyclerView <\/code><\/pre>\n<p>  \u0421 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u044f\u043c\u0438 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0438\u0441\u044c, \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0439\u0434\u0435\u043c \u043a \u0441\u0430\u043c\u043e\u0439 \u0441\u043b\u0430\u0434\u043a\u043e\u0439 \u0447\u0430\u0441\u0442\u0438 \u2014 \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0435. \u041f\u0435\u0440\u0432\u043e-\u043d\u0430\u043f\u0435\u0440\u0432\u043e \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043a API, \u043f\u043e\u044d\u0442\u043e\u043c\u0443  <\/p>\n<h2>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u043a API<\/h2>\n<p>  Retrofit \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0446\u0435\u043d\u043d\u044b\u0439 REST-\u043a\u043b\u0438\u0435\u043d\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c POST, GET, PUT, DELETE. \u0414\u043b\u044f \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0442\u0438\u043f\u0430 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0430\u0441\u043f\u0435\u043a\u0442\u043e\u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442\u0441\u044f \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u0438. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0438\u0442\u044c, \u0447\u0442\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f GET \u0437\u0430\u043f\u0440\u043e\u0441, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043f\u0435\u0440\u0435\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <a href=\"https:\/\/habrahabr.ru\/users\/get\/\" class=\"user_link\">GET<\/a>, \u0434\u043b\u044f POST \u0437\u0430\u043f\u0440\u043e\u0441\u0430 <a href=\"https:\/\/habrahabr.ru\/users\/post\/\" class=\"user_link\">POST<\/a>, \u0438 \u0442\u0430\u043a \u0434\u0430\u043b\u0435\u0435. \u0412 \u0441\u043a\u043e\u0431\u043a\u0430\u0445 \u043a \u0442\u0438\u043f\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0441\u0442\u0430\u0432\u0438\u0442\u0441\u044f \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0430\u0434\u0440\u0435\u0441. \u0414\u043b\u044f \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u043e\u0437\u044c\u043c\u0435\u043c API GitHub&#8217;\u0430. \u041f\u043e\u043b\u043d\u044b\u0439 URL \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u0440\u0435\u043f\u043e\u0437\u0438\u0442\u043e\u0440\u0438\u0435\u0432 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0432 \u0432\u0438\u0434\u0435 <code>https:\/\/api.github.com\/users\/octocat\/repos<\/code>, \u0433\u0434\u0435  <\/p>\n<ul>\n<li><a href=\"https:\/\/api.github.com\/\">api.github.com<\/a> \u2014 \u0431\u0430\u0437\u043e\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0430\u0434\u0440\u0435\u0441\u0430 (\u0432\u0441\u0435\u0433\u0434\u0430 \u043e\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441\u043b\u0435\u0448\u0435\u043c)<\/li>\n<li>users\/{user}\/repos \u2014 \u043c\u0435\u0442\u043e\u0434 (\u0430\u0434\u0440\u0435\u0441 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430, \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0430\u0434\u0440\u0435\u0441), \u0433\u0434\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f (octocat) \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u0438\u043b\u0438 \u043d\u0430 \u0430\u043b\u0438\u0430\u0441 (\u043f\u0440\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u0430\u043b\u0438\u0430\u0441\u043e\u0432 \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435)<\/li>\n<\/ul>\n<p>  \u0415\u0449\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0442 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0437\u0430\u043f\u0440\u043e\u0441\u0430, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u0435 \u043a Umorili \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0430\u0434\u0440\u0435\u0441 \u2014 <code>http:\/\/www.umori.li\/api\/get?name=bash&num=50<\/code>, \u0433\u0434\u0435 <code>name=bash&num=50<\/code> \u2014 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<p>  \u041d\u043e \u043e\u0434\u043d\u0438\u043c\u0438 \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f\u043c\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043d\u0435 \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f, \u043d\u0430\u043c \u0436\u0435 \u043d\u0430\u0434\u043e \u0433\u0434\u0435-\u0442\u043e \u0438\u0445 \u043e\u043f\u0438\u0441\u0430\u0442\u044c. \u0410 \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u043c\u044b \u0438\u0445 \u0432 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 (interface). \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:  <\/p>\n<pre><code class=\"java\">package ru.mustakimov.retrofittutorial.api;  import java.util.List;  import retrofit2.Call; import retrofit2.http.GET; import retrofit2.http.Query; import ru.mustakimov.retrofittutorial.PostModel;  public interface UmoriliApi {     @GET(&quot;\/api\/get&quot;)     Call&lt;List&lt;PostModel&gt;&gt; getData(@Query(&quot;name&quot;) String resourceName, @Query(&quot;num&quot;) int count); } <\/code><\/pre>\n<p>  \u0420\u0430\u0437\u0431\u0435\u0440\u0435\u043c \u044d\u0442\u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u0423 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u043c\u0435\u0442\u043e\u0434 getData, \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u044e\u0449\u0438\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>Call&lt;List&lt;PostModel&gt;&gt;<\/code>. \u041c\u0435\u0442\u043e\u0434\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0441\u0435\u0433\u0434\u0430 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 <code>Call&lt;T&gt;<\/code> \u0438 \u0438\u043c\u0435\u0442\u044c \u0430\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044e \u0442\u0438\u043f\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 (GET, POST, PUT, DELETE). <br \/>  \u0410\u043d\u043d\u043e\u0442\u0430\u0446\u0438\u044f <code>@Query(&quot;name&quot;) String resourceName<\/code> \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442 Retrofit&#8217;\u0443, \u0447\u0442\u043e \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u043d\u0443\u0436\u043d\u043e \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043f\u0430\u0440\u0443 name=&lt;\u0417\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 resourceName&gt;.<\/p>\n<p>  \u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u0432 \u0446\u0435\u043b\u0435\u0432\u043e\u043c \u0430\u0434\u0440\u0435\u0441\u0435 \u0441\u0442\u043e\u0438\u0442 \u0430\u043b\u0438\u0430\u0441, \u0442\u043e \u0434\u043b\u044f \u0442\u043e\u0433\u043e, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u043c\u0435\u0441\u0442\u043e \u0430\u043b\u0438\u0430\u0441\u0430 \u043f\u043e\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435, \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c <code>@Path(&quot;&lt;\u041d\u0430\u0437\u0432\u0430\u043d\u0438\u0435 \u0430\u043b\u0430\u0441\u0430&gt;&quot;) SomeType variable<\/code>, \u0433\u0434\u0435 SomeType \u2014 \u043b\u044e\u0431\u043e\u0439 \u0442\u0438\u043f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, String, int, float).<\/p>\n<p>  PostModel \u2014 \u043a\u043b\u0430\u0441\u0441, \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0441\u0430\u0439\u0442\u043e\u043c <a href=\"http:\/\/www.jsonschema2pojo.org\">jsonschema2pojo<\/a> \u043d\u0430 \u043e\u0441\u043d\u043e\u0432\u0435 \u043e\u0442\u0432\u0435\u0442\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043e\u0442 \u0441\u0430\u043c \u043a\u043b\u0430\u0441\u0441<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.mustakimov.retrofittutorial;  import com.google.gson.annotations.Expose; import com.google.gson.annotations.SerializedName;  public class PostModel {      @SerializedName(&quot;site&quot;)     @Expose     private String site;     @SerializedName(&quot;name&quot;)     @Expose     private String name;     @SerializedName(&quot;desc&quot;)     @Expose     private String desc;     @SerializedName(&quot;link&quot;)     @Expose     private String link;     @SerializedName(&quot;elementPureHtml&quot;)     @Expose     private String elementPureHtml;      \/**      * @return The site      *\/     public String getSite() {         return site;     }      \/**      * @param site The site      *\/     public void setSite(String site) {         this.site = site;     }      \/**      * @return Site name      *\/     public String getName() {         return name;     }      \/**      * @param name Site name      *\/     public void setName(String name) {         this.name = name;     }      \/**      * @return Site description      *\/     public String getDesc() {         return desc;     }      \/**      * @param desc Site description      *\/     public void setDesc(String desc) {         this.desc = desc;     }      \/**      * @return The link      *\/     public String getLink() {         return link;     }      \/**      * @param link The link      *\/     public void setLink(String link) {         this.link = link;     }      \/**      * @return The elementPureHtml      *\/     public String getElementPureHtml() {         return elementPureHtml;     }      \/**      * @param elementPureHtml The elementPureHtml      *\/     public void setElementPureHtml(String elementPureHtml) {         this.elementPureHtml = elementPureHtml;     }  } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  <\/p>\n<h2>\u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043a\u0430 \u043a \u0437\u0430\u043f\u0440\u043e\u0441\u0443<\/h2>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0441\u0442\u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e Retrofit&#8217;\u0430 \u0438 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430. \u0427\u0442\u043e\u0431\u044b \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043d\u0435 \u0438\u043c\u0435\u043b\u043e \u0441\u043e\u0442\u043d\u044e \u043e\u0431\u044a\u0435\u043a\u0442\u043e\u0432, \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u044e\u0449\u0438\u0445 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u044e, \u043c\u044b \u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043c \u0432\u0441\u044e \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0432 \u043a\u043b\u0430\u0441\u0441\u0435, \u0443\u043d\u0430\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u043d\u043d\u043e\u043c \u043e\u0442 Application. \u041a\u043e\u0434 \u0442\u043e\u0433\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:  <\/p>\n<pre><code class=\"java\">package ru.mustakimov.retrofittutorial;  import android.app.Application;  import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; import ru.mustakimov.retrofittutorial.api.UmoriliApi;  public class App extends Application {      private static UmoriliApi umoriliApi;     private Retrofit retrofit;      @Override     public void onCreate() {         super.onCreate();          retrofit = new Retrofit.Builder()                 .baseUrl(&quot;http:\/\/www.umori.li\/&quot;) \/\/\u0411\u0430\u0437\u043e\u0432\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u0430\u0434\u0440\u0435\u0441\u0430                 .addConverterFactory(GsonConverterFactory.create()) \/\/\u041a\u043e\u043d\u0432\u0435\u0440\u0442\u0435\u0440, \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0439 \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f JSON'\u0430 \u0432 \u043e\u0431\u044a\u0435\u043a\u0442\u044b                 .build();         umoriliApi = retrofit.create(UmoriliApi.class); \/\/\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442, \u043f\u0440\u0438 \u043f\u043e\u043c\u043e\u0449\u0438 \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b     }      public static UmoriliApi getApi() {         return umoriliApi;     } } <\/code><\/pre>\n<p><i>P.S. \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432 \u043c\u0430\u043d\u0438\u0444\u0435\u0441\u0442\u0435 \u043f\u0440\u043e\u043f\u0438\u0441\u0430\u0442\u044c, \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u0441\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 Application<\/i><\/p>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0438\u0437 \u043b\u044e\u0431\u043e\u0433\u043e \u043a\u043b\u0430\u0441\u0441\u0430 \u043c\u044b \u0438\u043c\u0435\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a API.<\/p>\n<h2>\u041f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h2>\n<p>  \u041c\u044b \u043c\u043e\u0436\u0435\u043c \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c \u0437\u0430\u043f\u0440\u043e\u0441\u044b (\u0438, \u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435) \u0434\u0432\u0443\u043c\u044f \u0441\u043f\u043e\u0441\u043e\u0431\u0430\u043c\u0438 \u2014 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0430 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b\u043c\u0438 \u0437\u0430\u043f\u0440\u043e\u0441\u0430\u043c\u0438. \u0414\u043b\u044f \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e (\u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0449\u0435\u0433\u043e) \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c \u043c\u0435\u0442\u043e\u0434 <code>execute()<\/code> \u0443 \u043e\u0431\u044a\u0435\u043a\u0442\u0430 \u0442\u0438\u043f\u0430 Call. \u0414\u043b\u044f \u043d\u0430\u0448\u0435\u0433\u043e \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043a\u043e\u0434 \u0431\u044b\u043b \u0431\u044b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c:  <\/p>\n<pre><code class=\"java\">Response response = App.getApi().getData(&quot;bash&quot;, 50).execute(); <\/code><\/pre>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u043e\u0431\u044a\u0435\u043a\u0442 \u0442\u0438\u043f\u0430 Response (\u043e\u0442\u0432\u0435\u0442), \u043e\u0442\u043a\u0443\u0434\u0430 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0430\u0441\u043f\u0430\u0440\u0441\u0435\u043d\u043d\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u043c\u0435\u0442\u043e\u0434\u043e\u043c <code>body()<\/code>.<\/p>\n<p>  \u0414\u043b\u044f \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u044b \u0437\u0430\u043c\u0435\u043d\u044f\u0435\u043c <code>execute()<\/code> \u043d\u0430 <code>enqueue()<\/code>, \u0433\u0434\u0435 \u0432 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u0445 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u0432\u044b\u0437\u043e\u0432\u0430 (\u043a\u043e\u043b\u0431\u044d\u043a\u0438). \u0412 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u043d\u043e \u0442\u0430\u043a:  <\/p>\n<pre><code class=\"java\">App.getApi().getData(&quot;bash&quot;, 50).enqueue(new Callback&lt;List&lt;PostModel&gt;&gt;() {     @Override     public void onResponse(Call&lt;List&lt;PostModel&gt;&gt; call, Response&lt;List&lt;PostModel&gt;&gt; response) {         \/\/\u0414\u0430\u043d\u043d\u044b\u0435 \u0443\u0441\u043f\u0435\u0448\u043d\u043e \u043f\u0440\u0438\u0448\u043b\u0438, \u043d\u043e \u043d\u0430\u0434\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c response.body() \u043d\u0430 null     }     @Override     public void onFailure(Call&lt;List&lt;PostModel&gt;&gt; call, Throwable t) {         \/\/\u041f\u0440\u043e\u0438\u0437\u043e\u0448\u043b\u0430 \u043e\u0448\u0438\u0431\u043a\u0430     } }); <\/code><\/pre>\n<p>  <\/p>\n<h3>\u0414\u0435\u043b\u0430\u0435\u043c \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445<\/h3>\n<p>  \u0414\u0430\u043d\u043d\u044b\u0435 \u043c\u044b \u0443\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0438, \u0430 \u043a\u0430\u043a \u0438 \u0442\u0435\u043f\u0435\u0440\u044c \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c? \u041a\u0438\u0434\u0430\u0435\u043c \u0432 \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0443 \u0430\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 RecyclerView \u0438 \u043a\u0430\u043a-\u043d\u0438\u0431\u0443\u0434\u044c \u0435\u0433\u043e \u043e\u0431\u0437\u044b\u0432\u0430\u0435\u043c. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0442\u043a\u0443 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c \u0443 \u043c\u0435\u043d\u044f<\/b><\/p>\n<div class=\"spoiler_text\">activity_main.xml  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;RelativeLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;     xmlns:tools=&quot;http:\/\/schemas.android.com\/tools&quot;     android:id=&quot;@+id\/activity_main&quot;     android:layout_width=&quot;match_parent&quot;     android:layout_height=&quot;match_parent&quot;     tools:context=&quot;ru.mustakimov.retrofittutorial.MainActivity&quot;&gt;      &lt;android.support.v7.widget.RecyclerView         android:layout_width=&quot;match_parent&quot;         android:layout_height=&quot;match_parent&quot;         android:layout_alignParentTop=&quot;true&quot;         android:layout_alignParentLeft=&quot;true&quot;         android:id=&quot;@+id\/posts_recycle_view&quot;         android:layout_alignParentStart=&quot;true&quot; \/&gt; &lt;\/RelativeLayout&gt; <\/code><\/pre>\n<p>  post_item.xml  <\/p>\n<pre><code class=\"xml\">&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt; &lt;RelativeLayout xmlns:android=&quot;http:\/\/schemas.android.com\/apk\/res\/android&quot;     android:padding=&quot;5dp&quot;     android:layout_width=&quot;match_parent&quot;     android:layout_height=&quot;wrap_content&quot;&gt;      &lt;TextView         android:id=&quot;@+id\/postitem_post&quot;         android:layout_width=&quot;match_parent&quot;         android:layout_height=&quot;wrap_content&quot;         android:text=&quot;\u041e\u0447\u0435\u043d\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0439 \u043f\u043e\u0441\u0442 \u0441 \u0431\u0430\u0448\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0438\u043a\u0442\u043e \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0432\u0438\u0434\u0435\u043b, \u0442\u0430\u043a \u043a\u0430\u043a \u0435\u0433\u043e \u043d\u0435 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442&quot;         android:textColor=&quot;?android:attr\/textColorPrimary&quot;         android:layout_alignParentTop=&quot;true&quot;         android:layout_alignParentLeft=&quot;true&quot;         android:layout_alignParentStart=&quot;true&quot; \/&gt;      &lt;TextView         android:id=&quot;@+id\/postitem_site&quot;         android:layout_width=&quot;wrap_content&quot;         android:layout_height=&quot;wrap_content&quot;         android:text=&quot;Bash.im&quot;         android:layout_below=&quot;@+id\/postitem_post&quot;         android:layout_alignParentRight=&quot;true&quot;         android:layout_alignParentEnd=&quot;true&quot;         android:gravity=&quot;end&quot;         android:textAlignment=&quot;textEnd&quot; \/&gt; &lt;\/RelativeLayout&gt; <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0434\u043b\u044f RecyclerView  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.mustakimov.retrofittutorial;  import android.os.Build; import android.support.v7.widget.RecyclerView; import android.text.Html; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView;  import java.util.List;  public class PostsAdapter extends RecyclerView.Adapter&lt;PostsAdapter.ViewHolder&gt; {      private List&lt;PostModel&gt; posts;      public PostsAdapter(List&lt;PostModel&gt; posts) {         this.posts = posts;     }      @Override     public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {         View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.post_item, parent, false);         return new ViewHolder(v);     }      @Override     public void onBindViewHolder(ViewHolder holder, int position) {         PostModel post = posts.get(position);         if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.N) {             holder.post.setText(Html.fromHtml(post.getElementPureHtml(), Html.FROM_HTML_MODE_LEGACY));         } else {             holder.post.setText(Html.fromHtml(post.getElementPureHtml()));         }         holder.site.setText(post.getSite());     }      @Override     public int getItemCount() {         if (posts == null)             return 0;         return posts.size();     }      class ViewHolder extends RecyclerView.ViewHolder {         TextView post;         TextView site;          public ViewHolder(View itemView) {             super(itemView);             post = (TextView) itemView.findViewById(R.id.postitem_post);             site = (TextView) itemView.findViewById(R.id.postitem_site);         }     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0418 \u043f\u0440\u043e\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 MainActivity.java \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e RecyclerView, \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u0430, \u0430 \u0442\u0430\u043a \u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u0410 \u0432\u043e\u0442 \u0438 MainActivity<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"java\">package ru.mustakimov.retrofittutorial;  import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.widget.Toast;  import java.io.IOException; import java.util.ArrayList; import java.util.List;  import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response;  public class MainActivity extends AppCompatActivity {      RecyclerView recyclerView;     List&lt;PostModel&gt; posts;      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_main);          posts = new ArrayList&lt;&gt;();          recyclerView = (RecyclerView) findViewById(R.id.posts_recycle_view);         LinearLayoutManager layoutManager = new LinearLayoutManager(this);         recyclerView.setLayoutManager(layoutManager);          PostsAdapter adapter = new PostsAdapter(posts);         recyclerView.setAdapter(adapter);          try {             Response response = App.getApi().getData(&quot;bash&quot;, 50).execute();         } catch (IOException e) {             e.printStackTrace();         }          App.getApi().getData(&quot;bash&quot;, 50).enqueue(new Callback&lt;List&lt;PostModel&gt;&gt;() {             @Override             public void onResponse(Call&lt;List&lt;PostModel&gt;&gt; call, Response&lt;List&lt;PostModel&gt;&gt; response) {                 posts.addAll(response.body());                 recyclerView.getAdapter().notifyDataSetChanged();             }              @Override             public void onFailure(Call&lt;List&lt;PostModel&gt;&gt; call, Throwable t) {                 Toast.makeText(MainActivity.this, &quot;An error occurred during networking&quot;, Toast.LENGTH_SHORT).show();             }         });     } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041d\u0430 GitHub&#8217;\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u0430\u0439\u0442\u0438 \u043f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f \u2014 <a href=\"https:\/\/github.com\/Mikhail57\/RetrofitTutorial\">github.com\/Mikhail57\/RetrofitTutorial<\/a><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habrahabr.ru\/post\/314028\/\"> https:\/\/habrahabr.ru\/post\/314028\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/b4b\/a01\/0c6\/b4ba010c6d5a4cb4856e76f6072ed89e.jpg\"\/><\/p>\n<p>  \u0412 \u043c\u0438\u0440\u0435 Android \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a, \u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u0434\u0435\u0442\u0438\u0449\u0435 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 <a href=\"http:\/\/square.github.io\">Square<\/a> \u2014 <a href=\"http:\/\/square.github.io\/retrofit\/\">Retrofit<\/a>. \u0427\u0442\u043e \u0436\u0435 \u044d\u0442\u043e \u0437\u0430 \u0437\u0432\u0435\u0440\u044c \u0442\u0430\u043a\u043e\u0439? Retrofit (\u0441\u043e\u0433\u043b\u0430\u0441\u043d\u043e \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u0441\u0430\u0439\u0442\u0443) \u2014 \u0442\u0438\u043f\u043e\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u044b\u0439 HTTP-\u043a\u043b\u0438\u0435\u043d\u0442 \u0434\u043b\u044f Android \u0438 Java. \u0412 \u043c\u0438\u0440\u0435 \u0436\u0435 Android \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0445 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0439 \u2014 \u043d\u0435\u0437\u0430\u043c\u0435\u043d\u0438\u043c\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 API. \u041a\u0430\u043a\u0438\u0445-\u0442\u043e \u043b\u0435\u0442 5 \u043d\u0430\u0437\u0430\u0434 Android-\u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0430\u043c \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u0441\u0435\u0442\u044c\u044e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432\u043e\u0440\u043e\u0442\u0438\u0442\u044c \u0433\u043e\u0440\u044b \u043a\u043e\u0434\u0430 \u0441 \u043e\u0431\u0440\u0430\u0442\u043d\u044b\u043c\u0438 \u0432\u044b\u0437\u043e\u0432\u0430\u043c\u0438, AsyncTask&#8217;\u0430\u043c\u0438 \u0438 \u043f\u0440\u043e\u0447\u0438\u043c\u0438 \u00ab\u043d\u0438\u0437\u043a\u043e\u0443\u0440\u043e\u0432\u043d\u0435\u0432\u044b\u043c\u0438\u00bb \u0432\u0435\u0449\u0430\u043c\u0438. \u0418 \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u044f Square \u0432\u044b\u043f\u0443\u0441\u0442\u0438\u043b\u0430 \u0442\u0430\u043a\u0443\u044e \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u2014 Retrofit.<\/p>\n<p>  \u0412 \u0441\u0435\u0442\u0438 \u0418\u043d\u0442\u0435\u0440\u043d\u0435\u0442 \u043c\u043d\u0435 \u043d\u0435 \u0443\u0434\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u0439\u0442\u0438 \u0432\u043d\u044f\u0442\u043d\u044b\u0445 \u0442\u0443\u0442\u043e\u0440\u0438\u0430\u043b\u043e\u0432 \u043f\u043e \u0432\u0442\u043e\u0440\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0431\u0438\u0431\u0438\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f \u0441 \u043d\u0435\u0439 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043f\u043e\u043b\u0443\u0447\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u043e\u0441\u0442\u044b \u0441 bash.im  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-280279","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280279","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=280279"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/280279\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=280279"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=280279"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=280279"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}