- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
它不重复。我看到所有答案都是堆栈。我的问题:我有 CommentActivity,我在其中获取 Cursor。在 CommentCursorAdapter 中,我从数据库获取值。在适配器中,我有两个图像:喜欢和不喜欢。当我单击“赞”时,数据库中的评级会增加。TextView 评级应在按下后显示新的评级。如何正确地做到这一点?
评论 Activity
public class CommentActivity extends AppCompatActivity {
private String idComment;
private ListView listComments;
private CommentCursorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_comment);
listComments = (ListView) findViewById(R.id.list_comments);
idComment = getIntent().getStringExtra(MainActivity.ID_KEY);
getCursorData();
}
private void getCursorData() {
adapter = new CommentCursorAdapter(this, new CursorLoader(App.getInstance(), idComment).loadInBackground(), 0);
listComments.setAdapter(adapter);
}
private static class CursorLoader extends SimpleCursorAdapter {
private String idComment;
public CursorLoader(Context context, String idComment) {
super(context);
this.idComment = idComment;
}
@Override
public Cursor loadInBackground() {
return App.getInstance().getDb().rawQuery(
"SELECT comment._id AS _id, comment.text AS text, user.email AS email, comment.rate FROM comment JOIN user ON comment.userId = user._id WHERE comment.postId = ? ORDER BY _id ASC", new String[]{
idComment
});
}
}
}
CommentCursorAdapter
public class CommentCursorAdapter extends CursorAdapter {
private TextView commentEmail;
private TextView commentText;
private TextView ratingText;
private ImageView imageViewLike;
private ImageView imageViewDislike;
private static final String ID = "_id";
private static final String EMAIL = "email";
private static final String TEXT = "text";
private static final String RATE = "rate";
public CommentCursorAdapter(Context context, Cursor c, int flags) {
super(context, c, 0);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
return LayoutInflater.from(context).inflate(R.layout.adapter_comment, viewGroup, false);
}
@Override
public void bindView(View view, Context context, final Cursor cursor) {
commentEmail = (TextView) view.findViewById(R.id.comment_email);
commentText = (TextView) view.findViewById(R.id.comment_text);
ratingText = (TextView) view.findViewById(R.id.rating_text);
imageViewLike = (ImageView) view.findViewById(R.id.image_like);
imageViewDislike = (ImageView) view.findViewById(R.id.image_dislike);
imageViewLike.setTag(cursor.getString(cursor.getColumnIndexOrThrow(ID)));
imageViewDislike.setTag(cursor.getString(cursor.getColumnIndexOrThrow(ID)));
String email = cursor.getString(cursor.getColumnIndexOrThrow(EMAIL));
String text = cursor.getString(cursor.getColumnIndexOrThrow(TEXT));
String rating = cursor.getString(cursor.getColumnIndexOrThrow(RATE));
commentEmail.setText(email);
commentText.setText(text);
ratingText.setText(rating);
imageViewLike.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("like", "click");
SQLiteStatement statement = App.getInstance().getDb().compileStatement(
"UPDATE comment SET rate = rate + 1 WHERE comment._id = ?"
);
statement.bindString(1, (String) view.getTag());
try {
statement.execute();
} finally {
statement.close();
}
}
});
imageViewDislike.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("dislike", "click");
SQLiteStatement statement = App.getInstance().getDb().compileStatement(
"UPDATE comment SET rate = rate - 1 WHERE comment._id = ?"
);
statement.bindString(1, (String) view.getTag());
try {
statement.execute();
} finally {
statement.close();
}
//swapCursor(cursor);
//notifyDataSetChanged();
}
});
}
}
最佳答案
您可以选择一些选项:
ContentProvider
。如果您做得正确,提供程序可以通知所有加载器其基础数据已更改,因此它们会自动重新加载。关于android - 如何使用光标适配器刷新适配器中的评级,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38092228/
我正在使用 MySQL 和 PHP 为 Flash 游戏构建数据层。检索关卡列表非常简单,但我在尝试获取关卡的平均评分及其指针信息时遇到了障碍。这是一个示例数据集: 级别表: level_id | l
阅读 schema.org 之后我写了一个小的“丰富代码片段”或者它所谓的什么。我们今天被谷歌找到,但没有显示星级和评级。也许有人对此有经验并且知道事情是如何完成的?它仅取决于微数据还是取决于 中的
有没有一种方法(或 API)可以使远程 SMF 站点排队以获取特定时间范围内的热门/热门主题,比如过去 24 小时?如果没有,关于我如何跟踪它有什么建议吗? 最佳答案 不确定这是否可行,但我知道 SM
有谁知道如何使用 Foursquare API 获取 field 的分数/评级(例如 9.0/10)? 我正在通过无用户访问进行连接。 https://developer.foursquare.com
我正在使用 Sonar 来分析一组相关的项目。 我正在使用 SQALE 评级来证明重构的必要性 我的问题是 SQALE 到技术债务比率映射背后的逻辑是什么? 为什么 SQALE A 评级是技术债务,范
我有一份 FIFA 19 两名球员之间的比赛列表,我希望根据所参加的比赛使用该数据更新我在这两名球员之间的 ELO 评分。我正在尝试使用此数据不断更新最初从 1000 开始的 ELO 评级。 我尝
我无法显示评级元素。它根本就没有出现。所有其他事情都很好 我已经正确地链接了这些: 语义用户界面 CSS ( http://semantic-ui.com/dist/semantic.min.css
我正在开发一个 Java 应用程序,其中涉及使用 Foursquare 来搜索 field 。该应用程序预计也会对场馆进行评级。除了场馆的收视率之外,我已经做了所有我需要做的事情。我阅读了利用 fou
由于我公司的一位客户要求标记图像上的 alt 属性,我遇到了 google maps API 的问题。 我在谷歌官方文档中找不到任何内容(即:https://developers.google.com
有人可以给我一个 onRate() 的例子吗? Semantic UI 中评级小部件的回调函数 ( http://semantic-ui.com/modules/rating.html#/settin
我有四个主表- 1.user(user_id, name,...) 2. post(post_id, description, ...) 3.comment(comment_id,user_id,co
我已登录并获取身份验证 token ,但当我单击“赞”按钮时,YouTube 评级不起作用。我还需要做什么才能让它发挥作用?如果我在网络浏览器中使用该网址,它会要求授权并执行,然后它就可以工作。但从应
我正在使用我在网上找到的一些评级系统 CSS。目前我能够让它工作,但是当显示多个评级时会出现问题。 只有最后一个分级类有效。 .rate { float: left; pointer-even
我安装了一个应用程序 django- ratings。我想要syncdb,但这是我的错误: djangoratings.vote: 'user' defines a relation with the
每个人都喜欢在他们的网站上显示 Digg/Tweet/Like 徽章,而 Disqus Comment System开始接管。 (来源:disqus.com) (来源:digg.com) 从开发人员的
我有一个 Bootstrap Rating 组件,我必须使用 on-leave 方法来调用我的 javascript 函数。除了 IE 之外,所有其他浏览器也在单击事件上执行 on-leave 函数。
我正在用 Rating Bootstrap 做一个 MVC 应用程序。 我也定义了这个...为了知道点击了多少开始。 $(document).ready(function () {
我想按人口统计(性别、年龄组)收集 IMDb 评级详细信息。 当我尝试在 imdbpy 中使用 get_movie_vote_details 模块时,我的输出为空。这是我的代码: import im
我正在尝试使用 PHP 和 SoapClient 来利用 UPS Ratings 网络服务。我找到了一个名为 WSDLInterpreter 的好工具来创建用于创建服务请求的起点库,但无论我尝试什么,
我正在尝试向现有表格添加“评级”系统(即 1 星、2 星或差、一般、好、优秀等)。有谁知道在 .Net 或免费的第 3 方控件中通过良好的 UX 实现美观的方法? 谢谢 最佳答案 检查 ASP.NET
我是一名优秀的程序员,十分优秀!