I want to fetch only particular data from json object using id and show it in textview. I am able fetch data in listview. But i want fetch data without using listview into basic textview. using each id.
**Only want Fetch id="1" json data and display it into textview name,mobile,age,email. After clicking button **
Json Data
{
"details": [
{
"age": "56",
"email": "john@gmail.com",
"id": "1",
"mobile": "985323154",
"name": "John"
},
{
"age": "0",
"email": "",
"id": "26",
"mobile": "0",
"name": "1"
}
]
}
DisplayData Class
public class DisplayData extends AppCompatActivity {
String BASE_URL = "";
ArrayList<String> id = new ArrayList<>();
ArrayList<String> name = new ArrayList<>();
ArrayList<String> age = new ArrayList<>();
ArrayList<String> mobile = new ArrayList<>();
ArrayList<String> email = new ArrayList<>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list);
displayData();
}
public void displayData() {
RestAdapter adapter = new RestAdapter.Builder()
.setEndpoint(BASE_URL) //Setting the Root URL
.build();
AppConfig.read api = adapter.create(AppConfig.read.class);
api.readData(new Callback<JsonElement>() {
@Override
public void success(JsonElement result, Response response) {
String myResponse = result.toString();
Log.d("response", "" + myResponse);
try {
JSONObject jObj = new JSONObject(myResponse);
int success = jObj.getInt("success");
if (success == 1) {
JSONArray jsonArray = jObj.getJSONArray("details");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jo = jsonArray.getJSONObject(i);
id.add(jo.getString("id"));
name.add(jo.getString("name"));
age.add(jo.getString("age"));
mobile.add(jo.getString("mobile"));
email.add(jo.getString("email"));
}
}
@Override
public void failure(RetrofitError error) {
Log.d("Failure", error.toString());
Toast.makeText(DisplayData.this, error.toString(), Toast.LENGTH_LONG).show();
}
}
);
}
}