dynamically add imagebutton programatically android

Posted by user1266179 on Stack Overflow See other posts from Stack Overflow or by user1266179
Published on 2012-04-13T11:14:58Z Indexed on 2012/04/13 11:29 UTC
Read the original article Hit count: 169

Filed under:

I am getting dynamic length of the string array and i want to display images in the imagebutton and that too in horizontal view as i had added button but it shows in the vertical layout.Please help. This is my code:

     for (int i =0;i<adapt_objmenu.image_array.length;i++){
         ImageButton b1 = new ImageButton(myrefmenu);
            b1.setId(100 + i);

           // b1.setText(adapt_objmenu.city_name_array[i]);
            RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
            if (i > 0) {
                lp.addRule(RelativeLayout.BELOW, b1.getId() - 1);
            }   
            b1.setLayoutParams(lp);
            relative.addView(b1);

    //relate.addView(b1, i,  new RelativeLayout.LayoutParams(width,height));

    //height = height+80;



    }

© Stack Overflow or respective owner

Related posts about android