Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi .
im developing an android application ,
but i have a little problem .
i want to make 10 buttons dynamically.
if i set Button text directly it works and it creates 10 buttons very well.

Java
LinearLayout ll=(LinearLayout)findViewById(R.id.lil);
for(int i=0 ;i<=9;i++)
{
Button B=new Button(this);
B.setTextSize(TypedValue.COMPLEX_UNIT_DIP,10);
B.setText("1");
ll.addView(B); 
}

but as you see if i want to set text like below it makes only one button without any text !

Java
String BtnText="";
String temp="";
String []DD=new String [3];
LinearLayout ll=(LinearLayout)findViewById(R.id.lil);
for(int i=0 ;i<=9;i++)
		{
			temp=SplitData[i];
			DD=temp.split("/");
			BtnText=DD[0].toString();
			Button B=new Button(this);
			B.setTextSize(TypedValue.COMPLEX_UNIT_DIP,10);
			B.setText(BtnText);
			ll.addView(B);			
			
		}


surprisely i debugged my application line by line and couldnt see any problem .everything works well, i dont have any Exception but as i said it makes only one Button without any text !

so i need help , do you have any suggestion ?
Posted
Updated 19-Dec-14 2:06am
v3
Comments
Richard MacCutchan 19-Dec-14 11:10am    
I just ran your code and it created the buttons fine. The only difference is that I had a fixed string in temp so I did not use the line
temp=SplitData[i]; and I only create three buttons.
seyed mahmud shahrokni 19-Dec-14 13:41pm    
what do you think ? how can i solve my problem ?
Richard MacCutchan 20-Dec-14 4:12am    
You have to identify what is happening, and why your buttons are not showing on he screen. Are you sure that the XML for your LinearLayout element is correct, and will accept the buttons? Are you sure that each button is being created correctly in the loop?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900