I know this is the answer, but I couldn't add it to my code.
How can I return value from function onResponse of Volley? <------
like here I created interface. I did it all. I just don't know how to convert this my code to it, and how to use the return value in other activities.
public void priceDate(Context contex, final String coin) {
String URL = "https://min-api.cryptocompare.com/data/top/exchanges/full?fsym=BTC&tsym=USD&api_key=" + apiKey;
//String a =
//json_Parser = new JSONParser(_usd);
RequestQueue requestQueue = Volley.newRequestQueue(contex);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, URL, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
//Log.d("Main",response.toString());}
DecimalFormat formatter = new DecimalFormat("#,###,###");
String yourFormattedString = formatter.format(100000);
try {
JSONObject Data = response.getJSONObject("Data");
JSONObject AggregatedData = Data.getJSONObject("AggregatedData");
try {
String Price = AggregatedData.getString("PRICE");
String formatPrice = formatter.format(Math.round(Float.valueOf(Price)));
_price.setText("Price :" + formatPrice);
} catch (Error e) {
_price.setText("Data Not Avvaliable");
}
try {
String Open = AggregatedData.getString("OPENDAY");
String formatOpen = formatter.format(Math.round(Float.valueOf(Open)));
_open.setText("Open :" + formatOpen);
} catch (Error e) {
_open.setText("Data Not Avvaliable");
}
try {
String Low = AggregatedData.getString("LOWDAY");
String formatLow = formatter.format(Math.round(Float.valueOf(Low)));
_low.setText("Low :" + formatLow);
} catch (Error e) {
_low.setText("Data Not Avvaliable");
}
try {
String High = AggregatedData.getString("HIGHDAY");
String formatHigh = formatter.format(Math.round(Float.valueOf(High)));
_high.setText("High :" + formatHigh);
} catch (Error e) {
_high.setText("Data Not Avvaliable");
}
try {
String Volume = AggregatedData.getString("VOLUMEDAY");
String formatVol = formatter.format(Math.round(Float.valueOf(Volume)));
_volume.setText("Volume :" + formatVol);
} catch (Error e) {
_volume.setText("Data Not Avvaliable");
}
try {
String LastUpdate = AggregatedData.getString("LASTUPDATE");
String convert = unix_time(Long.parseLong(LastUpdate));
_lastUpdate.setText("Last Update :" + LastUpdate);
} catch (Error e) {
_lastUpdate.setText("Data Not Avvaliable");
}
try {
String TradeId = AggregatedData.getString("LASTTRADEID");
_tradeId.setText("Trade Id :" + String.valueOf(Math.round(Float.parseFloat(TradeId))));
} catch (Error e) {
_tradeId.setText("Data Not Avvaliable");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonObjectRequest);
}