什么是排球更新UI的最有效的方法 [英] What is the most efficient way of updating UI in Volley
问题描述
最近我用排枪库机器人。它工作正常,但我想知道更新UI ..最有效的方式我有了所有凌空方法utils的类..现在我通过所有视图将被更新的参数,但我读过,我可以在我的活动实施听众然后将它们传递作为utils的类的参数。
lately I'm using Volley library in android.. It works fine but I was wondering about the most efficient way of updating the UI.. I have a Utils class that has all the Volley methods.. right now I pass all the Views that will be updated as parameters, but I've read that I could implement the listeners in my activity then pass them as parameters in the Utils class..
所以我的问题是:
这是更有效,为什么更新UI是这样的:
Which is more efficient and why updating the UI like this:
public void getSettings(final TextView exampleView) {
JsonObjectRequest jsonRequest = new JsonObjectRequest(Method.GET,
url, (String) null, new Response.Listener<JSONObject>() {
public void onResponse(JSONObject response) {
try {
final String setting = getSettingFromJSON(response);
exampleView.setText(setting);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
public void onErrorResponse(VolleyError arg0) {
}
});
app.add(jsonRequest);
}
或者我宣布我的活动听众是这样的:
Or I declare the listeners in my activity like this :
Response.Listener<JSONObject> listener = new Response.Listener<JSONObject>() {
public void onResponse(JSONObject response) {
String setting = Utils.getSettingFromJSON(response);
exampleView.setText(setting);
}
};
然后我将它们传递到我的utils的功能参数,以便调用将是这样的:
then I pass them into my utils function as parameters so the call would be like this :
utils.getSettings(listener);
而不是:
utils.getSettings(exampleView);
在此先感谢:)
推荐答案
正如我的问题<一href=\"http://stackoverflow.com/questions/31602042/android-java-how-to-delay-return-in-a-method/31604258\">Android/Java:如何延缓的方法回报
我也用接口监听器,不过,我更新主线程看法,并不在utils的类
I also use interface listener, however, I update views in main thread, not in Utils class
这篇关于什么是排球更新UI的最有效的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!