I love this, understand life as it is.
Download app:
public interface DetailsAPI { @GET("/key/value/one/two") void insertUser(Callback<JsonObject> jsonObjectCallback);}public class MainActivity extends AppCompatActivity { TextView tv; ListView listView; List<String> stringList = new ArrayList<>(); public static final String Root_url = "http://echo.jsontest.com/"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv = (TextView) findViewById(R.id.tv_response); listView = (ListView) findViewById(R.id.listview); insertUser(); ArrayAdapter<String> stringArrayAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, stringList); listView.setAdapter(stringArrayAdapter); } private void insertUser() { RestAdapter adapter = new RestAdapter.Builder().setEndpoint(Root_url).build(); DetailsAPI api = adapter.create(DetailsAPI.class); api.insertUser(new Callback<JsonObject>() { @Override public void success(JsonObject jsonObject, Response response) { if (response.getStatus() == 200) tv.setText("You got the data"); String jsonResponse = jsonObject.get("one").getAsString(); stringList.add(jsonResponse); jsonResponse = jsonObject.get("key").getAsString(); stringList.add(jsonResponse); //*********************Json response is too short so the same above values are stored in list array repeatedly.... ************** jsonResponse = jsonObject.get("one").getAsString(); stringList.add(jsonResponse); jsonResponse = jsonObject.get("key").getAsString(); stringList.add(jsonResponse); jsonResponse = jsonObject.get("one").getAsString(); stringList.add(jsonResponse); jsonResponse = jsonObject.get("key").getAsString(); stringList.add(jsonResponse); } public void failure(RetrofitError error) { Toast.makeText(MainActivity.this, "try again!", Toast.LENGTH_SHORT).show(); } }); }}<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello Response here" android:textColor="#ff2323" android:textSize="22sp" android:id="@+id/tv_response" /> <ListView android:id="@+id/listview" android:layout_below="@+id/tv_response" android:layout_width="match_parent" android:layout_height="100dp"> </ListView></RelativeLayout>after put this line don't forget to sync it.
dependencies {
compile 'com.squareup.retrofit:retrofit:1.9.0'
}