Hi, I'm trying to create a grid of clickable views from an array, and
the following code places all of the view on top of eachother. What am
I doing wrong?

                 for(int ct = 0; ct<max; ct++) {
                        final int pos = ct;

                        LayoutParams layout = new LayoutParams(24,24);
                        viewArray[ct].setBackgroundColor(colorArray[ct]);
                        viewArray[ct].setMinimumHeight(24);
                        viewArray[ct].setMinimumWidth(24);
                        viewArray[ct].setOnClickListener(new 
View.OnClickListener() {

                                @Override
                                public void onClick(View arg0) {
                                        setColor(pos);
                                }
                        });

                        //Positioning
                        if(ct % 6 == 0 ) { //If we need to make a new row
                                if(rowCt != 0) { //If it's not the first row
                                        
layout.addRule(RelativeLayout.ALIGN_PARENT_LEFT,
RelativeLayout.TRUE);
                                        ++rowCt;
                                } else { //If its the first box
                                        
layout.addRule(RelativeLayout.ALIGN_PARENT_LEFT,
RelativeLayout.TRUE);

                                }

                        } else {
                                if(rowCt!=0) {
                                        layout.addRule(RelativeLayout.BELOW, 
viewArray[ct-6].getId());
                                        layout.addRule(RelativeLayout.RIGHT_OF, 
viewArray[ct-1].getId());
                                } else {
                                        
layout.addRule(RelativeLayout.ALIGN_PARENT_TOP,
RelativeLayout.TRUE);
                                        layout.addRule(RelativeLayout.RIGHT_OF, 
viewArray[ct-1].getId());
                                }
                        }
                        viewArray[ct].setLayoutParams(layout);
                        colorPicker.addView(viewArray[ct]);
                }

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to android-beginners@googlegroups.com
To unsubscribe from this group, send email to
android-beginners-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to