0

I have a relative layout with textviews ordered in more then one column. When clicked on screen, there is a "popup screen" or "input screen" (have no idea how it is called) in which I define the time "from" and "to", what is the name of school class etc. It will compute which textviews it needs to merge from that input. Merged textviews have to be like one larger textview. Is it possible to do something like this?

Thanks for the answer in ahead.

Something like this: https://i.stack.imgur.com/r1o8D.png

Beemo
  • 441
  • 6
  • 18
  • A new window? This is a little ambiguous. Do you want your table in a dialog? In a layout? Created programmatically at runtime? You've written it will compute so i'm assuming your table needs to be dynamic? Could you please edit the question – cjds Dec 05 '12 at 16:06
  • @CarlSaldanha edited. More clear now? I even got an idea to transform programmically one textview to a larger one with changing his height. – Beemo Dec 05 '12 at 18:12
  • Instead of creating textviews like so couldn't you just create one text view per column. And go to the next line for a new row? You can draw the lines with a custom view – cjds Dec 06 '12 at 11:49
  • @CarlSaldanha defined textview can span on more then one row, and they have to be colored after defining the input. Any code would be very appreciated. And thanks for the idea. – Beemo Dec 06 '12 at 14:21

1 Answers1

0

I've got an idea you could try creating a custom view to draw this instead of using views.

Extend the View class in a new class and override the onDraw method.

//variables
Paint paint[]; //Set up these paints with the colors you need
int rowWidth, int colHeight;
void onDraw(Canvas c){
    for(int i=0;i<noOfRows;i++){
       for(int j=0;j<noOfColumns;j++){
            if(cellRequired(i,j)){
              //cellRequired will be whatever logic you have to check if cell is required

                int rectHeight=colHeight; //Now the Rect Height changes whether the cell
                                         //  below is in use or not.
                for(int k=i;k<noOfRows;k++){                         
                     //This loop will run through the rows and see if merging is required
                      if(cellRequired(i,k))
                             rectHeight+=colHeight; //Merge Cell
                      else 
                              break; //If not required at any point break loop
                 }
                 //Draw Rectangle background
                 c.drawRect(i*rowWidth +i, j*colHeight +j, rowWidth, rectHeight, backPaint);
                 //Draw Text
                 canvas.drawText("Text",i*rowWidth +i, j*colHeight +j, paint[requiredPaint]);
                 //I added the plus i and plus j so there'd be a gap in the rectangles
                 // Then it will be a border
            }         
       }
    }
}

Android documentation on custom controls you

Android: Tutorial on Custom View creation

How to make a custom view similar to above

http://www.droidnova.com/playing-with-graphics-in-android-part-i,147.html

Go through these and then through the code above. Hopefully it should show you how to implement it.

Community
  • 1
  • 1
cjds
  • 8,268
  • 10
  • 49
  • 84
  • You mean, one custom view per column? Will study more about custom view and will be back. Thanks for you help, for now :) – Beemo Dec 06 '12 at 17:36
  • Actually this custom view draws the entire table... Rows columns merged cells..ultiple text colors.. Everything. Check out the code. See if it'll suit you – cjds Dec 07 '12 at 01:21
  • When that custom view draws everything I need, next time I start the application, it will be the same or it will restart to blank? Can you show me your idea with more code? I would be very grateful to you. Still, thank you very much for your help even if you now don't have time for helping me further. – Beemo Dec 08 '12 at 22:39
  • I'm confused. The custom view above will allow you to draw the table with merged views. Where you get the data to draw the table is your thing. There is a method cellRequired(i,j). I haven't specified it. Its a method you have to implement if cell is required. Got it or are you still confused? Every time you start the app you'll have to get the data and put it in just like you're doing with your present Activity (if you like the answer please upvote it) – cjds Dec 09 '12 at 02:52
  • I'm clearly new to this so it's all still confusing. If you could make me some code sample so I can see this in working, it would be much better. Thanks. – Beemo Dec 09 '12 at 21:14
  • Edited the answer. I included some links to show you what custom views can do. Go through them and then through my code. Should help (if you like the answer please upvote it) – cjds Dec 10 '12 at 07:32