the id is an intiger value not string: hope u ll get an idea from below code
while (ctr<3)
{
int layoutid;
if(ctr==1)
{ layoutid = R.id.AbsoluteLayout1;}
else{
layoutid = R.id.AbsoluteLayout2;}
mainlayout[ctr] = (AbsoluteLayout)findViewById(layoutid);
ctr++;
}
---------------------------------------------
all these won post an error as they are handled as int itself manipulate as you want you cant use this as it is as
int[] ctra={R.id.xx,R.id.xxx};
int i=0;
while (ctr<3)
{
mainlayout[i]=(AbsoluteLayout)findViewById(ctra[i]);
i++;}
I solved it using getIdentifier method
Button[] buttons;
for(int i=0; i<buttons.length; i++) {
{
String buttonID = "sound" + (i+1);
int resID = getResources().getIdentifier(buttonID, "id", getPackageName());
buttons[i] = ((Button) findViewById(resID));
buttons[i].setOnClickListener(this);
}