mardi 30 décembre 2014

checkbox id replace from previous android java

I have created dynamically checkbox for each title like below:


door



  • wooden

  • aluminiun


window



  • wooden

  • aluminiun


I am getting title from this piece of code:



for (int i = 0; i < arr.length; i++) {
if (DValue.contains(arr[i])) {
DValue = DValue.replace(arr[i], "");
}
if (Title.contains(arr[i])) {
Title = Title.replace(arr[i], "");
}
}


and set checkbox id here:



for (int a = 0; a < data.length; a++) {
cb[a] = new CheckBox(this);
cb[a].setId(a);
RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
(int) LayoutParams.WRAP_CONTENT,
(int) LayoutParams.WRAP_CONTENT);
param.leftMargin = 25;
// param.topMargin = (a + 1) * (105 + add1 -sub);
param.topMargin = add1;
cb[a].setPadding(45, 20, 25, 5); // cb[a].setPadding(5, 23, 5,
// // 5);
cb[a].setLayoutParams(param);
cb[a].setText(data[a].trim());
if (strMultiChk != null)
{
strMultiChk.replaceAll("\\s","");
String cb_text = cb[a].getText().toString();
String[] arr1 = TextUtils.split(strMultiChk, ";");
//String[] arr1 = strMultiChk.split("[")[1];
for(int i = 1; i < arr1.length; i++)
{
if(arr1[i].contains(Title) && strMultiChk.contains(cb_text))
{
cb[a].setChecked(true);
}
}
}
layout.addView(cb[a]);
// add = add + 25;
// add1 = add1 + 15;
add1 = add1 + 35;
}


the problem is that it set both checkbox for 1st title i.e door but for 2nd title i.e window it replace the id of both checkboxes from previous two:


Kindly suggest me, how can I resolve it.


waiting for reply.


Thanks.





Aucun commentaire:

Enregistrer un commentaire