首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AQuery到Retofit

AQuery到Retofit
EN

Stack Overflow用户
提问于 2017-08-27 02:51:10
回答 1查看 88关注 0票数 0

我听说Retrofit更简单也更有用。因为AQuery最初是用来下载图像的,所以它不适合与服务器进行网络连接。我看了文件,但我不明白。如果我看到一个例子,我想我能理解。这里有没有人能举例说明如何将此代码更改为Retofit

第一个代码是使用url从服务器获取值。

代码语言:javascript
复制
public class PastQuestionFragment extends Fragment {
AQuery aq = new AQuery(getActivity());
String postUrl = "http://192.168.0.21:3000/SendPastQuestion";

TextView pastQuestion;

@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup 
container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) 
inflater.inflate(R.layout.fragment_pastquestion, container, false);
    pastQuestion = (TextView) rootView.findViewById(R.id.pastquestion);


    aq.ajax(postUrl, JSONObject.class, new AjaxCallback<JSONObject>() {
        @Override
        public void callback(String url, JSONObject json, AjaxStatus status) 
{
            if (json != null) {
                Log.d("debug", "json is not null");
                try {
                    pastQuestion.setText(json.getString("pastquestion"));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            } else {
                Log.d("debug", "json is null");
            }
        }
    });
    return rootView;
}
}

第二个代码是使用post发送值。

代码语言:javascript
复制
public void postSignUpData(String name, String id, String password, String email) {
    String postUrl = "http://192.168.0.21:3000/SignUp";
    Map<String, Object> params = new HashMap<>();
    params.put("name", name);
    params.put("id", id);
    params.put("password", password);
    params.put("email", email);

    aq.ajax(postUrl, params, String.class, new AjaxCallback<String>() {
        @Override
        public void callback(String url, String json, AjaxStatus status) {
            if (json != null) {
                Toast.makeText(aq.getContext(), "Status1 : " + status.getCode() + " + " + json.toString(), Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(aq.getContext(), "Status2 : " + status.getCode(), Toast.LENGTH_SHORT).show();
            }
        }
    });
}

我只是个学生所以。请详细解释一下。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2017-08-27 03:05:50

我建议阅读以下内容:

1-无需改造即可下载照片:

https://stackoverflow.com/a/25463200/7709267

2-如果您想使用改进,您可以在此链接中查看示例

https://futurestud.io/tutorials/retrofit-2-how-to-download-files-from-server

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45898659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档