简体   繁体   English

LinkedList 和 RadioButton

[英]LinkedList and RadioButton

I have a LinkedList of all the selected answers of a user through radio buttons.我通过单选按钮有一个用户所有选定答案的 LinkedList。 I wish to set them as selected when revisited by picking up the earlier set answers in the LinkedList.我希望在重新访问时通过在 LinkedList 中选择较早设置的答案将它们设置为选中状态。 How can this be achieved?如何做到这一点?

selected=(String) dtmarked.get(dtqno.indexOf(queno)-1);
System.out.println("SELECTED: "+selected);
if(selected.equals("choice1"))
    choice1.setSelected(true);
else if(selected.equals("choice2"))
    choice2.setSelected(true);
else if(selected.equals("choice3"))
    choice3.setSelected(true);
else if(selected.equals("choice4"))
    choice4.setSelected(true);

I tried following the above snipet but without success even though it prints the correct choice number.我尝试按照上面的片段进行操作,但即使它打印了正确的选择编号,也没有成功。 here dtmarked is my linkedlist这里 dtmarked 是我的链表

  public void choice()
    {

        if(choice1.isSelected())
        {   
            if(dtmarked.size()!=cnt)
                dtmarked.add("choice1");
            else
            {
                dtmarked.remove(dtqno.indexOf(queno));
                dtmarked.add(dtqno.indexOf(queno),"choice1");
            }
        }
        else if(choice2.isSelected())
        {   
            if(dtmarked.size()!=cnt)
                dtmarked.add("choice2");
                else
                {
                    dtmarked.remove(dtqno.indexOf(queno));
                    dtmarked.add(dtqno.indexOf(queno),"choice2");
                }
        }
        else if(choice3.isSelected())
        {
            if(dtmarked.size()!=cnt)
            dtmarked.add("choice3");
            else
            {
                dtmarked.remove(dtqno.indexOf(queno));
                dtmarked.add(dtqno.indexOf(queno),"choice3");
            }
        }
        else if(choice4.isSelected())
        {
            if(dtmarked.size()!=cnt)
            dtmarked.add("choice4");
            else
            {
                dtmarked.remove(dtqno.indexOf(queno));
                dtmarked.add(dtqno.indexOf(queno),"choice4");
            }
        }      
        else
        {           
            if(dtmarked.size()!=cnt)
            dtmarked.add("0");
            else
            {
                dtmarked.remove(dtqno.indexOf(queno));
                dtmarked.add(dtqno.indexOf(queno),"0");
            }
        }
        System.out.println(dtqno);
        System.out.println(dtmarked);
    }

This is what I have done to add the choices in the linked list.这就是我在链接列表中添加选项所做的工作。 also here cnt is a variable returning number of entries in a table(in this case 5).这里的 cnt 也是一个返回表中条目数的变量(在本例中为 5)。

You shouldn't use else if because then only one of the if/else if blocks gets executed.您不应该使用 else if,因为这样只会执行 if/else if 块之一。 You should only use if.你应该只使用如果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM