예제 #1
0
  private void addComment() {
    NewsdalyComment comment = new NewsdalyComment();
    DalyNews dalyNews = new DalyNews();
    cur_user = BmobUser.getCurrentUser(this, User.class);
    String getid = getIntent().getStringExtra("id");
    String user_name = cur_user.getUsername();
    TextView tx = new TextView(this);
    tx.setTextSize(15);
    tx.setPadding(5, 15, 5, 7);
    String content_c = ed_newscomment.getText().toString();
    tx.setText("用户:" + user_name + "\n" + content_c);
    dalyNews.setObjectId(getid);
    comment.setComment(content_c);
    comment.setDalyNews(dalyNews);
    comment.setCommenter(cur_user);
    comment.setCommentname(user_name);
    comment.save(
        this,
        new SaveListener() {

          @Override
          public void onSuccess() {
            // TODO Auto-generated method stub
            Toast.makeText(NewsDaylyActivity.this, "评论已添加", Toast.LENGTH_SHORT).show();
          }

          @Override
          public void onFailure(int arg0, String arg1) {
            // TODO Auto-generated method stub
            Toast.makeText(NewsDaylyActivity.this, "服务器暂未响应!", Toast.LENGTH_SHORT).show();
          }
        });

    layout_content.addView(tx);
  }
예제 #2
0
  private void querydata() {
    BmobQuery<NewsdalyComment> query = new BmobQuery<NewsdalyComment>();
    DalyNews dalyNews = new DalyNews();
    String i = getIntent().getStringExtra("id");
    dalyNews.setObjectId(i);
    query.addWhereEqualTo("dalyNews", new BmobPointer(dalyNews));
    query.findObjects(
        this,
        new FindListener<NewsdalyComment>() {

          @Override
          public void onSuccess(List<NewsdalyComment> object) {
            // TODO Auto-generated method stub
            for (NewsdalyComment content : object) {
              String c = content.getComment();
              String name = content.getCommentname();
              TextView tx = new TextView(NewsDaylyActivity.this);
              tx.setTextSize(15);
              tx.setText("用户:" + name + "\n" + c);
              layout_content.addView(tx);
            }
          }

          @Override
          public void onError(int arg0, String arg1) {
            // TODO Auto-generated method stub
            Toast.makeText(NewsDaylyActivity.this, "服务器暂未响应!", Toast.LENGTH_SHORT).show();
          }
        });
  }