Parse.com存储问题

时间:2015-05-21 18:33:19

标签: android android-studio parse-platform

所以我试图实现一个功能,您可以在listview中对对象进行投票,就像使用upvote和downvote系统的reddit一样。我认为系统很简单,你按下upvote按钮,它会增加总分,但我遇到了一些问题。第一个问题是,当我按下upvote时,分数上的数字会增加但是当我刷新Parse数据库时,数字不会存储。当我重新启动应用程序时,分数也不会保存,因此看起来所有发生的事情都是列表增量上的分数但不保存。第二个问题是减量,我尝试做与增量相同的事情,但似乎没有像增量一样改变数字的函数(即增量(" PostScore&#) 34;,1),它只有减量())。如果我只使用decrement(),我会遇到NullPointer错误。

这是我的queryAdapter:

    // Set up the query adapter
    postsQueryAdapter = new ParseQueryAdapter<AnywallPost>(this, factory) {
        @Override
        public View getItemView(final AnywallPost post, View view, ViewGroup parent) {
            if (view == null) {
                view = View.inflate(getContext(), R.layout.anywall_post_item, null);
            }
            //TextView DetailsView = (TextView) view.findViewById(R.id.content_view);
            TextView contentView = (TextView) view.findViewById(R.id.content_view);
            TextView usernameView = (TextView) view.findViewById(R.id.username_view);
            TextView postscoreView = (TextView) view.findViewById(R.id.PostScore);
            RadioButton upvote = (RadioButton) view.findViewById(R.id.Upvote);
            RadioButton downvote = (RadioButton) view.findViewById(R.id.DownVote);

            //DetailsView.setText(post.getDetails());
            contentView.setText(post.getText());
            usernameView.setText(post.getUser().getUsername());
            postscoreView.setText(post.getInt().toString());
            upvote.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    post.increment();
                }
            });
            downvote.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    //post.decrement();
                }
            });

            return view;
        }
    };

这是我的帖子的getter和setter活动:

package com.binarsunset.topic;

import com.parse.ParseClassName;
import com.parse.ParseGeoPoint;
import com.parse.ParseObject;
import com.parse.ParseQuery;
import com.parse.ParseUser;

/**
 * Data model for a post.
 */
@ParseClassName("Posts")
public class AnywallPost extends ParseObject {

    public void increment() { increment("PostScore", 1);
    saveInBackground();
    }

    public void decrement() { decrement(); }

    public String getText() {
        return getString("text");
    }

    public void setText(String value) {
        put("text", value);
    }

    public ParseUser getUser() {
        return getParseUser("user");
    }

    public void setUser(ParseUser value) {
        put("user", value);
    }

    public ParseGeoPoint getLocation() { return getParseGeoPoint("location"); }

    public void setLocation(ParseGeoPoint value) {
        put("location", value);
    }

    public void setInt(int number){ put("PostScore", number); }

    public Number getInt(){ return getNumber("PostScore"); }

    public String getDetails() {
        return("Details");
    }

    public void setDetails (String value){
        put("Details", value);
    }

    public static ParseQuery<AnywallPost> getQuery() {
        return ParseQuery.getQuery(AnywallPost.class);
    }
}

我认为问题可能在于我如何使用saveInBackground,但我可能非常错误。如果需要更多代码,请告诉我。谢谢。

0 个答案:

没有答案