カード オブジェクトとユーザー オブジェクトの間に解析関係を作成しようとしています。ユーザーがカスタム arrayadapter で同様のボタンを連続してクリックすると、「保存されました」というメッセージが表示されますが、Parse databrowser にリレーションが追加されません!
これがカスタムarrayadapterのコードです
public class CardAdapter extends ArrayAdapter<ParseObject> {
public static final String TAG = CardAdapter.class.getSimpleName();
protected Context mContext;
protected List<ParseObject> mCards;
protected ParseRelation<ParseObject> mCardsLikeRelation;
protected ParseUser mCurrentUser;
public CardAdapter(Context context, List<ParseObject> cards) {
super(context, R.layout.card_item, cards);
mContext = context;
mCards = cards;
mCurrentUser = ParseUser.getCurrentUser();
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if(convertView == null){
convertView = LayoutInflater.from(mContext).inflate(R.layout.card_item, parent, false);
holder = new ViewHolder();
holder.CardImageView = (ImageView) convertView.findViewById(R.id.cardImage);
holder.CardContent = (TextView) convertView.findViewById(R.id.cardText);
holder.CardLikeButton = (Button)convertView.findViewById(R.id.likeButton);
convertView.setTag(holder);
}
else{
holder = (ViewHolder) convertView.getTag();
}
final ParseObject card = mCards.get(position);
if(card != null) {
mCardsLikeRelation = mCurrentUser.getRelation("cardLikesRelation");
holder.CardContent.setText(card.getString("content"));
holder.CardLikeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(mContext, card.getObjectId(),
Toast.LENGTH_LONG).show();
mCardsLikeRelation.add(card);
mCurrentUser.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if (e != null) {
Log.e(TAG, e.getMessage());
}
else{
Log.e(TAG, "saved");
}
}
});
}
});
}
return convertView;
}
private static class ViewHolder{
ImageView CardImageView;
TextView CardContent;
Button CardLikeButton;
TextView CardLikes;
ProgressBar progress;
}
public void refill(List<ParseObject> cards){
mCards.clear();
mCards.addAll(cards);
notifyDataSetChanged();
}
}