【问题标题】:Android RadioButton return a constant?Android RadioButton 返回一个常量?
【发布时间】:2009-10-16 21:40:07
【问题描述】:

我正在尝试执行一个评级系统,其中选择的选项返回一个常数,因此我可以将一个值插入数据库。我的意图是有 3 个选择,“Great”、“Mediocre”和“Bad”。我希望 Great 成为 '3' 的常数,Mediocre 有一个常数 '2' 和 Bad 有一个常数 '1'。如果可能的话,我想只插入数值,有什么简单的方法吗?

安东尼

【问题讨论】:

    标签: database android radio-button constants


    【解决方案1】:

    RadioGroup 具有 getCheckedRadioButtonId() 方法,该方法返回所选 RadioButton 的资源 ID。

    您可以设置如下开关盒:

    private static final int CHOICE_GREAT = 3;
    private static final int CHOICE_MEDIOCRE = 2;
    private static final int CHOICE_BAD = 1;
    
    int selected = getRating();
    
    private int getRating() {
        switch (ratingGroup.getCheckedRadioButtonId()) {
           case R.id.RadioButtonGreat:
              return CHOICE_GREAT;
           case R.id.RadioButtonMediocre:
              return CHOICE_MEDIOCRE;
           case R.id.RadioButtonBad:
              return CHOICE_BAD;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2012-08-14
      • 2015-11-02
      • 1970-01-01
      • 1970-01-01
      • 2015-06-20
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 1970-01-01
      相关资源
      最近更新 更多