LeanCloud 功能封装

为君一笑 提交于 2020-03-02 22:41:38

直接贴代码吧

public class LeanCloudHelper {
    //连上数据库
    public void link() {
        AVOSCloud.initialize(MyApplication.getContext(),
                "appid",
                "appkey",
                "serverURL");
    }
//设置textview
    public void setText(String className, String ObjectId, final String key, final TextView textView) {
        AVQuery<AVObject> query = new AVQuery<>(className);


        query.getInBackground(ObjectId).subscribe(new Observer<AVObject>() {
            public void onSubscribe(Disposable disposable) {}
            public void onNext(AVObject avObject) {
                String value= avObject.getString(key);
                textView.setText(value);
            }
            public void onError(Throwable throwable) {}
            public void onComplete() {}
        });
    }
    //设置imageview
    public void setImage(String className, String ObjectId, final String key, final ImageView imageView) {
        AVQuery<AVObject> query = new AVQuery<>(className);

        query.getInBackground(ObjectId).subscribe(new Observer<AVObject>() {
            public void onSubscribe(Disposable disposable) {}
            public void onNext(AVObject avObject) {
                String web= avObject.getString(key);
                Glide.with(imageView).load(web).into(imageView);

            }
            public void onError(Throwable throwable) {}
            public void onComplete() {}
        });
    }



}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!