【问题标题】:setChecked and setSelected in CheckBox not workingCheckBox 中的 setChecked 和 setSelected 不起作用
【发布时间】:2019-10-09 03:06:07
【问题描述】:

我有一个 Activity,它在寻呼机中有 5 个片段。我用过

 viewPager.setOffscreenPageLimit(fragmentList.size());

能够一次创建所有片段 我还有一个监听器,一旦我有了 newIntent,它就会将参数(对象)传递给所有片段。

在我的一个片段中,我有 CheckBox,应该根据活动的参数进行选择。 和其他观点,我能够改变他们的文本和背景的价值。 只是这个复选框我已经设置它但是当我看到它时,我看到它是关闭的,所有其他事件都运行良好。

这里是活动

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.AppTheme_PopupOverlay);
    setContentView(R.layout.activity_configurations);

    ViewPager viewPager = findViewById(R.id.container);
    TabLayout tabLayout = findViewById(R.id.tabs);

    setNdef(getIntent().getExtras());
    String type = getNdef().getString("id");

    List<Fragment> fragmentList = createFragments(type);
    SectionsPagerAdapter pagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager(), fragmentList);
    viewPager.setAdapter(pagerAdapter);

    fillTableLayout(tabLayout, type);

    viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
    tabLayout.addOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
    tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
    viewPager.setOffscreenPageLimit(fragmentList.size());
    readNfcDialog = createReadDialog();
    writeNfcDialog = createWriteDialog();
    readNfcDialog.show();
    setForeground();
}

 @Override
protected void onNewIntent(Intent intent) {

    super.onNewIntent(intent);

   
    ClassNfcTag wepTag = new ClassNfcTag(intent);
    String type = wepTag.defineClassTag();
    OmsRepeaterTag omsRepeaterTag = new OmsRepeaterTag(intent);
    byteMap = omsRepeaterTag.readTag();
   if (byteMap != null) {
   setTagOmsConfiguration(OmsConfiguration.fromByteArray(byteMap));
   for (OmsListener listener : onReceiveOmsList) {
        listener.gotOms(getInTagOmsConfiguration());
       }
   }
}

这是其中一个片段

    @Override
public void gotOms(OmsConfiguration configuration) {
    setConfiguration(configuration);
    if (isAdded()) {
    boolean status = getConfiguration().getDeleteRsl();
    delete.setChecked(status);
    delete.setSelected(status);

    }
}

作为一种解决方案,我尝试使用 Switch 而不是 CheckBox,并且效果很好。

我还尝试将寻呼机设置为从具有 CheckBox 的片段开始,它也可以工作。

viewPager.setCurrentItem(checkBoxFragmentPosition);

我还尝试调试代码,它显示复选框已选中,当我尝试通过触摸将其更改为已选中时(以编程方式已选中,在 UI 中我看到未选中),它会自行从未选中更改为未选中。然后在下一次触摸时更改为选中。

【问题讨论】:

    标签: java android checkbox interface


    【解决方案1】:

    仅针对将阅读此问题的人,这只是 android 中未解决的错误。 对于我的情况,我使用了toggleButton 而不是checkBox

    【讨论】:

      猜你喜欢
      • 2012-04-21
      • 2016-11-10
      • 1970-01-01
      • 2020-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-02
      • 2013-03-26
      相关资源
      最近更新 更多