0
我是新來的android和我正在開發一個應用程序,從bitrex獲取當前速率並將其轉換爲印度盧比,但問題是我想刷新每秒鐘的速度,但我的處理程序只運行一次,第一次後,並沒有改變其值,即使在利率苯甲地那銨API爲什麼我的處理程序只運行一次刷新數據
在改變這就是我的活動
public class Test extends AppCompatActivity {
double last;
double inr;
double x;
TextView tv, tt, ui,uer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
uer=(TextView)findViewById(R.id.usern);
ui = (TextView) findViewById(R.id.uid);
tv = (TextView) findViewById(R.id.name);
tt = (TextView) findViewById(R.id.email);
final RequestQueue queue = Volley.newRequestQueue(this);
final RequestQueue queuee = Volley.newRequestQueue(this);
String url = "https://bittrex.com/api/v1.1/public/getticker?market=usdt-btc";
String urll="http://api.fixer.io/latest?base=USD";
final StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject json = null;
try {
json = new JSONObject(response);
} catch (JSONException e) {
e.printStackTrace();
}
try {
JSONObject result = json.getJSONObject("result");
last = result.getDouble("Last");
tv.setText(String.valueOf(last));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
final StringRequest stringRequestmoney = new StringRequest(Request.Method.GET, urll,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
JSONObject jjson = null;
try {
jjson = new JSONObject(response);
} catch (JSONException e) {
e.printStackTrace();
}
try {
JSONObject money = jjson.getJSONObject("rates");
inr = money.getDouble("INR");
tt.setText(String.valueOf(inr));
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
// queue.add(stringRequest);
// queuee.add(stringRequestmoney);
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
//do something
queue.add(stringRequest);
queuee.add(stringRequestmoney);
x = (last * inr);
ui.setText(""+x);
handler.postDelayed(this, 5000);
}
}, 5000);
}
你怎麼知道處理程序再也沒有調用過? – nhoxbypass
因爲在API中的速率變化,但沒有在我的Android應用程序中改變@GeniusQ –