Carlos kambui

Carlos kambui

  • NA
  • 499
  • 117k

dynamic button in android studio

Jun 10 2019 1:15 AM
hi everyone,i have managed to add button dynamically in android studio,
my question is i wont to declare that button public so that i can be able to access it
 
below is my code
  1. for (int i=1;i<=5; i++)  
  2. {  
  3.     final Button btn= new Button(this);  
  4.     btn.setLayoutParams(new LinearLayout.LayoutParams(250,250));  
  5.     btn.setId(i);  
  6.     btn.setText("DATABASE" +i);  
  7.     btn.setText(itemArrayList.get(i).getCategory_desc()+"");  
  8.     layout.addView(btn);  
  9. }  
i cant acces that button outside that for loop
 
any assistance will be appreciated

Answers (3)