android评论模块
private void setViewclick(){
Dialog dialog = new Dialog(mActivityContext, R.style.DialogTheme);
//dialog_shoppcart
View view = View.inflate(mActivityContext,R.layout.dialog_comment,null);
dialog.setContentView(view);
btncommentout = view.findViewById(R.id.btn_comment_out);
editcomment = view.findViewById(R.id.edit_comment_comments);
textViewRemainingWords = view.findViewById(R.id.tv_comment_zishu);
btnsendout = view.findViewById(R.id.btn_comment_sendout);
pingjia_star = view.findViewById(R.id.pingjia_star);
//关闭评论弹窗
btncommentout.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) { dialog.dismiss();}
});
//监听输入框剩余字数
editcomment.addTextChangedListener(new TextWatcher() {
int wordLimitNum= 100;
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { }
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) { enterWords = s; }
@Override
public void afterTextChanged(Editable s) {
//已输入字数
enteredWords= wordLimitNum - s.length();
//TextView显示剩余字数
textViewRemainingWords.setText(100 - enteredWords+ "/100");
selectionStart = editcomment.getSelectionStart();
selectionEnd = editcomment.getSelectionEnd();
if (enterWords.length() > wordLimitNum) {
//删除多余输入的字(不会显示出来)
s.delete(selectionStart - 1, selectionEnd);
int tempSelection = selectionEnd;
editcomment.setText(s);
//设置光标在最后
editcomment.setSelection(tempSelection);
}
}
});
//提交评论
btnsendout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String comment_text = editcomment.getText().toString();
if (!Tools.isNotNull(comment_text)){
editcomment.setError("评价不能为空");
return;
}
if (comment_text.length() > 100){
editcomment.setError("字数超长");
return;
}
String url = ServiceUrls.getReserveMethodUrl("insertComments");
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
String dateTime = format.format(new Date(System.currentTimeMillis()));
int goolemnt = (int) pingjia_star.getProgress();
float a = pingjia_star.getProgress();
Map<String,Object> map = new HashMap<>();
map.put("memberId",myApplication.getLoginMember().getMemberId());
map.put("menuid",menu.getMenuid());
map.put("commentTime",dateTime);
map.put("comment",comment_text);
map.put("goolment",goolemnt);
map.put("ReserveOrderDetailId",ReserveOrderDetailId);
OkHttpTool.httpPost(url, map, new OkHttpTool.ResponseCallback() {
@Override
public void onResponse(final boolean isSuccess,final int responseCode,final String response, Exception exception) {
mActivityContext.runOnUiThread(new Runnable() {
@Override
public void run() {
String strtext = "无法访问服务器,请检查网络连接";
if (isSuccess && responseCode == 200){
try {
JSONObject jsonObject = new JSONObject(response);
int code = jsonObject.getInt("code");
strtext = jsonObject.getString("text");
if (code == 200){
List<CommentVo> zion = new ArrayList<>();
zion = null;
commentAdapter.addItem(zion,1);
loadListData(true,menu.getMenuid());
editcomment.setText("");
dialog.dismiss();
Toast.makeText(mActivityContext,strtext,Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
Toast.makeText(mActivityContext,strtext,Toast.LENGTH_LONG).show();
}
});
}
});
}
});
dialog.show();
显示图