android评论模块

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();

显示图
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值