Blackberry - custom logic for checkboxes group
- by SWATI
if i click on any checkbox all previous checkboxes must get checked
"my logic works"
if i uncheck a checkbox then all checkboxes after it must get unchecked
"how to do that"
MyLogic works for storm but not for other models
what to do
//well what i want to do is i have 5 checkboxes
class myscreen
{
chk_service = new CheckboxField[5];
chk_service[0]= new CheckboxField("1",true)
chk_service[1]= new CheckboxField("2",false)
chk_service[2]= new CheckboxField("3",false)
chk_service[3]= new CheckboxField("4",false)
chk_service[4]= new CheckboxField("5",false)
CheckboxFieldChangeListener obj =
new CheckboxFieldChangeListener(chk_service);
chk_service[0].setChangeListener(obj);
chk_service[1].setChangeListener(obj);
chk_service[2].setChangeListener(obj);
chk_service[3].setChangeListener(obj);
chk_service[4].setChangeListener(obj);
hm4 = new HorizontalFieldManager();
hm4.add(chk_service[0]);
hm4.add(chk_service[1]);
hm4.add(chk_service[2]);
hm4.add(chk_service[3]);
hm4.add(chk_service[4]);
add(hm4);
}
public CheckboxFieldChangeListener (CheckboxField[] arrFields)
{
m_arrFields = arrFields;
}
public void fieldChanged(Field field, int context)
{
if(true == ((CheckboxField) field).getChecked())
{
for(int i = 0; i < m_arrFields.length; i++)
{
if(m_arrFields[i]==field)
{
//a[j]=i;
j++;
break;
}
else
{
CheckboxField oField = m_arrFields[i];
oField.setChecked(true);
}
}
}
a[k] = j;
if(false == ((CheckboxField) field).getChecked())
{
for(int i =field.getIndex(); i < m_arrFields.length; i++)
{
if(m_arrFields[i]==field)
{
//a[j]=i;
j++;
break;
}
else
{
CheckboxField oField = m_arrFields[i];
oField.setChecked(false);
}
}
}
}
}