开发者

j2me+choice group

开发者 https://www.devze.com 2023-03-01 01:49 出处:网络
I am working on the project where i had used choice group in form. Now I wan开发者_StackOverflow社区t to get the selected item or index number of the choice group and want to perform some action.

I am working on the project where i had used choice group in form. Now I wan开发者_StackOverflow社区t to get the selected item or index number of the choice group and want to perform some action.

I had tried through this:-

System.out.println(cgPrefs.getString(i) + (selected[i] ? ": selected" : ": not selected"));

But I am not getting the exact index number of the selected item in choice group.


You will get flags according to selection

boolean[] selectedFlag = new boolean[getChoiceGroup().size()];

using getSelectedFlags() method

getChoiceGroup().getSelectedFlags(selectedFlag);//getChoiceGroup() returns object of choicegroup

Now iterate and print

for(int i = 0 ; i < selectedFlag.length; i ++){
  if(selectedFlag[i]){
    System.out.println("Selected : "+getChoiceGroup().getString(i));
  }else{
    System.out.println("Not Selected : "+getChoiceGroup().getString(i));
  }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消