即使在setText之后,芯片文本也为空

时间:2019-12-06 15:38:51

标签: java android material-design android-chips

  

即使调用chip.setText(),Chip.getText()。toString()也为空

即使调用chip.setText("any Dummy Text"),我也已调试和测试。但是当我在调试时评估chip.getText().toString()。即使在设置文字的下一行之后也为空

源代码

for (TagBO tagItem : tagBOS) {
            final Chip newChip = new Chip(Favourite_Tag.this);
            newChip.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT));
            newChip.setChipDrawable(ChipDrawable.createFromAttributes(Favourite_Tag.this, null,
                    0, R.style.Widget_MaterialComponents_Chip_Filter));
            newChip.setText(tagItem.getTagName()); 
            newChip.setId(num); 
            // even after setting text I debug it here like newChip.getText().toString()

            newChip.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    if (!categories_Selected.contains(newChip.getText().toString())) {  // getText().toString() is "" 
                        categories_Selected.add(newChip.getText().toString());
                       // Toast.makeText(Favourite_Tag.this, ""+, Toast.LENGTH_SHORT).show();
                    } else {
                        categories_Selected.remove(newChip.getText().toString());
                    }
                    Toast.makeText(Favourite_Tag.this, ""+newChip.getText(),Toast.LENGTH_SHORT).show();
                   // model.updateCategoryFireStore(categories_Selected);
                }
            });
    }

问题已解决

升级到com.google.android.material:material:1.2.0-alpha02后,问题已解决

0 个答案:

没有答案