再次单击时如何取消取消选择单选按钮?

时间:2018-12-17 15:54:39

标签: java android android-layout kotlin radio-button

我已经成功实现了凌空抽射按钮。我的截击中的示例数据是1, 2, 3。当我选择单选按钮1,然后选择单选按钮2时,未选中单选按钮1。这种情况是正常的,但是当我再次选择单选按钮2时,单选按钮被取消选择,因此我无法再选择它。

这是我放入适配器的代码:

@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
    SharedPreferences sharedPreferences = context.getSharedPreferences(AppConfig.APP_PUPUKKUJANG_MART, Context.MODE_PRIVATE);
    final String whois = sharedPreferences.getString(AppConfig.USER_WHOIS,null);
    row_index = -1;
    holder.itemView.setTag(service.get(position));
    final ServiceCourier p = service.get(position);
    holder.service.setText(p.getService());
    holder.desc.setText(p.getDescription());
    holder.cost.setText("Rp "+String.format(Locale.US, "%1$,.0f", Double.valueOf(p.getCost())).replace(",","."));
    holder.etd.setText(p.getEtd());
    holder.itemView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
    View.OnClickListener rbClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RadioButton checked_rb = (RadioButton) v;
            if(lastCheckedRB != null){
                ActivityCheckout.updateTextViewIscek("0");
                lastCheckedRB.setChecked(false);
            }
            lastCheckedRB = checked_rb;
            SharedPreferences sharedPreferences = context.getSharedPreferences(AppConfig.APP_, Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPreferences.edit();
            editor.putString("ongkir_service", p.getService());
            editor.putString("ongkir_description", p.getDescription());
            editor.putString("ongkir_cost", p.getCost());
            editor.putString("ongkir_etd", p.getEtd());
            editor.apply();
            String cost = String.format(Locale.US, "%1$,.0f", Double.valueOf(p.getCost()));
            Double total_order = ActivityCheckout.getTextViewTotal();
            Double tf = Double.valueOf(p.getCost())+total_order;
            ActivityCheckout.updateTextViewIscek("1");
            ActivityCheckout.updateTextView("Rp "+cost.replace(",","."));
            ActivityCheckout.updateTotal_fees("Rp "+String.format(Locale.US, "%1$,.0f", tf).replace(",","."));
        }
    };
    holder.radiobutton.setOnClickListener(rbClick);
}

0 个答案:

没有答案