views:

30

answers:

0

In this method we are drawing edittext along with gridview . I am getting both.But the problem arises when i want to add another textbox in the same layout without the help of paint.see after code

public UIGridView(Vector _heading, Vector _columnid, Vector _datatype,
   Vector gridvector, Display display, Context context, EditText ed,
   boolean disp) {
  super(context);
  gridTxt = ed;
  if (disp)
   displacement = 3;
  else
   displacement = 5;
  // Spliting Grid Values
  this.display = display;
  // this.fullvector = gridvector;
  setFocusable(true);
  setFocusableInTouchMode(true);
  data = new Vector();
  heading = _heading;
  controlId = _columnid;
  dataType = _datatype;
  int NO_OF_COLUMN = heading.size();
  data = gridvector;

  System.out.println("*********GRID**********" + data);
  if (data.size() != 0) {
   String text = "";
   System.out.println("--------" + data.elementAt(0));
   Vector v1 = (Vector) data.elementAt(0);
   text = v1.elementAt(0).toString();
   System.out.println("--------" + text);
   gridTxt.setText(text);
   gridTxt.setFocusable(false);
   gridTxt.setFocusableInTouchMode(false);
   gridTxt.setCursorVisible(false);
   gridTxt.setClickable(false);

  }
  // System.out.println("CCCVVVVVVVVVVVVVVVVVVVVVVVVVV
  // :"+data.elementAt(1));
  // Screen Width & Height
  SCREEN_WIDTH = display.getWidth() - 5;
  // SCREEN_HEIGHT = display.getHeight() - 15;
  int temp_screen_h = Cell_HEIGHT * 5;

  if (temp_screen_h < display.getHeight()) {
   SCREEN_HEIGHT = temp_screen_h;
  } else {
   SCREEN_HEIGHT = display.getHeight() - 5;
  }
  System.out.println("value is screen 5555555555height" + SCREEN_HEIGHT);

  // Cell Width Details
  arr_cellW = new int[NO_OF_COLUMN];
  arr_Width_details = new int[NO_OF_COLUMN];
  Paint paint = new Paint();
  paint.setTextSize(18);
  paint.ascent();
  for (int i = 0; i < NO_OF_COLUMN; i++) {
   // String sb_heading = (String) heading.elementAt(i);
   // arr_cellW[i] = (int)
   // paint.measureText(heading.get(i).toString());
   // try{
   // lenthval = Integer.parseInt(String.valueOf(length.elementAt(i)));
   // }catch(Exception e){
   // lenthval = 1;
   // }
   arr_cellW[i] = 60;
   int widthheasing = (int) paint.measureText(heading.get(i)
     .toString());

   if (widthheasing > arr_cellW[i]) {
    arr_cellW[i] = widthheasing;
   }

  }
  // Initializing X_index values

  x_index = cur_cell_col_index;
  int w = 0, i = 0;
  for (i = x_index; w <= SCREEN_WIDTH && i < NO_OF_COLUMN; i++) {// col
   // System.out.println(i + " cols Width=" + arr_cellW[i]);
   w += arr_cellW[i] + 10;

  }
  if (SCREEN_WIDTH <= w) {
   itrate = true;
  }
  x_last_index = i - 1;
  total_col = x_last_index;
  // System.out.println(" Before x_index=" + x_index + " x_last_index="
  // + x_last_index + "  CUR COL " + cur_cell_col_index);

  // Initializing y_index values

  y_index = cur_cell_row_index;
  total_row = (SCREEN_HEIGHT / Cell_HEIGHT);
  y_last_index = total_row;
  // System.out.println(" Before y_index=" + y_index + "  y_last_index="
  // + y_last_index + "Cur Row " + cur_cell_row_index
  // + " total_row : " + total_row);
 }








protected void onDraw(Canvas g) {
  System.out.println("***********GRID Enters**********" + g);
  // System.out.println("*******draw*********" + x_index + "*
  // ********* "
  // + x_last_index);
  // scrollByX=0;
  setFocusable(true);
  // *********Draw Heading**********
  String sb_Heading = null;
  int hi = 0, x = 5, sb_lenght_cell = 0, y = 0;

  Paint header_bg_paint = new Paint();
  for (hi = x_index; hi <= x_last_index; hi++) {
   System.out.println("Heading Value::::"
     + heading.elementAt(hi).toString());

   sb_Heading = heading.elementAt(hi).toString();
   header_bg_paint.setTextSize(18);
   // header_bg_paint.setStyle(Style.STROKE);

   header_bg_paint.setColor(getResources()
     .getColor(R.color.Grid_title));

   if (x + sb_lenght_cell < SCREEN_WIDTH) {
    System.out.println("onDraw 1");
    // Cell Within Screen
    sb_lenght_cell = arr_cellW[hi] + 10;
    System.out.println("onDraw 2");
    g.drawRect(x + 1, y, x + sb_lenght_cell, y + Cell_HEIGHT - 1,
      header_bg_paint);
    header_bg_paint.setColor(Color.WHITE);
    int widthheasing = (int) header_bg_paint.measureText(heading
      .get(hi).toString());

    if (widthheasing > arr_cellW[hi]) {
     System.out.println("onDraw 3");
     int len = ((sb_Heading.length() * sb_lenght_cell) / widthheasing);

     // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> : "
     // + sb_Heading.length() + ">>>>>>>> " +
     // arr_cellW[hi]
     // + ">>>>>>>>>>>> :" + widthheasing + ">>>>>>>>>"
     // + len);
     sb_Heading = sb_Heading.substring(0, len - 2) + "...";
    }
    g.drawText(sb_Heading, x + 5, y + 28, header_bg_paint);
    x = x + sb_lenght_cell;

   } else {

    // LastCell Exciding Screen
    System.out.println("onDraw 4");
    g.drawRect(x + 1, y, SCREEN_WIDTH, y + Cell_HEIGHT - 1,
      header_bg_paint);
    header_bg_paint.setColor(Color.WHITE);
    // if (sb_heading.length() > arr_cellW[hi]) {
    System.out.println("onDraw 5");
    sb_Heading = sb_Heading.substring(0, 3);
    // }
    g.drawText(sb_Heading + "...", x + 5, y + 28, header_bg_paint);
    System.out.println("onDraw 6");
    x = x + sb_lenght_cell;

   }
    System.out.println("UUUUUUUUUUUUUUUUUUU" + hi);
   arr_Width_details[hi] = x;
  }
  x = 5;
  y = y + Cell_HEIGHT;
  sb_Heading = null;
  sb_lenght_cell = 0;

  // Draw Records or row
  int i, j;
  int numofres = data.size();
  Paint fground = new Paint();
  fground.setTextSize(18);
  // paint.setStyle(Paint.Style.FILL);
  // paint.setColor(Color.WHITE );
  fground.setColor(getResources().getColor(R.color.puzzle_hilite));
  Paint foreground = new Paint(Paint.ANTI_ALIAS_FLAG);

  foreground.setColor(getResources().getColor(R.color.puzzle_foreground));
   System.out.println("FFFFFFFFFFFFFFFFFFFFFFFFF "+y_index);
  if (data.size() != 0) {
   for (j = y_index; y < SCREEN_HEIGHT && j <= data.size(); j++) {// row
    // 
    // System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    // ::: "+j);
    System.out.println("onDraw 7");
    for (i = x_index; i <= x_last_index
      && x_last_index <= heading.size(); i++) {// col
     // Focu Event
     if (cur_cell_col_index == i && cur_cell_row_index == j) {
      System.out.println("onDraw 8");
      // System.out.println("Current col " +
      // cur_cell_col_index
      // + "cur_cell_row_index" + cur_cell_row_index);
      Paint paint = new Paint();

      paint.setTextSize(18);
      paint.setColor(getResources().getColor(
        R.color.cell_select_color));

      if (x + sb_lenght_cell < SCREEN_WIDTH) {
       sb_lenght_cell = arr_cellW[i] + 10;
       System.out.println("onDraw 9");
       g.drawRect(x + 2, y + 1, x + sb_lenght_cell - 1, y
         + Cell_HEIGHT - 2, paint);

      } else {
       g.drawRect(x + 2, y + 1, SCREEN_WIDTH, y
         + Cell_HEIGHT - 2, paint);
       System.out.println("onDraw 10");
      }
     } else {
      if (x + sb_lenght_cell < SCREEN_WIDTH) {
       // Grid Rectangledraw for cell inside the width
       sb_lenght_cell = arr_cellW[i] + 10;
       System.out.println("onDraw 11");
       g.drawRect(x + 1, y, x + sb_lenght_cell, y
         + Cell_HEIGHT - 1, fground);

      } else {
       // Grid Rectangledraw for cell OUTSIDE the width
       g.drawRect(x + 1, y, SCREEN_WIDTH, y + Cell_HEIGHT
         - 1, fground);
       System.out.println("onDraw 12");
      }
      // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>> "
      // + (y + Cell_HEIGHT));
     }
     // Draw String for cells
     try {
      // System.out.println("@@@@@@@@@@@@@@@@@@@@@@String
      // : "+i+"::::::: "+(j-1));
      String title = (String) heading.elementAt(i);
      sb_Heading = (String) ((Vector) data.elementAt(j - 1))
        .elementAt(i);
      // System.out.println("@@@@@@@@@@@@@@@@@@@@@@String
      // : "+sb_Heading);
      int widthheasing = (int) header_bg_paint
        .measureText(sb_Heading.toString());

      if (widthheasing > arr_cellW[i]) {
       int len = ((sb_Heading.length() * sb_lenght_cell) / widthheasing);
       // 
       // System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
       // :
       // "+sb_Heading.length()+">>>>>>>>
       // "+arr_cellW[i]+">>>>>>>>>>>>
       // :"+widthheasing+">>>>>>>>>"+len);
       System.out.println("onDraw 13");
       sb_Heading = sb_Heading.substring(0, len - 2)
         + "...";
      }
      foreground.setTextSize(18);
      System.out.println("what is text value" + sb_Heading);
      g.drawText(sb_Heading, x + 5, y + 28, foreground);
      x = x + sb_lenght_cell;

     } catch (Exception e) {
      // System.out.println("@@@@####@@@####@@@@@# " + e);
     }
    }
    y = y + Cell_HEIGHT;
    if (y > SCREEN_HEIGHT) {
     itratehit = false;
    }
    sb_Heading = null;
    sb_lenght_cell = 0;
    x = 5;
   }
  }

 }
   @Override
 protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  // TODO Auto-generated method stub
  System.out.println("On Measure ::::: w=" + widthMeasureSpec + " h="
    + heightMeasureSpec);
  System.out.println("On Measure ::::: w=" + getWidth() + " h="
    + getHeight());
  System.out.println("On Measure ::::: w=" + getWidth() + " h="
    + getHeight());
  // super.onMeasure(getWidth(), getHeight());
  setMeasuredDimension(getWidth(), SCREEN_HEIGHT);
  System.out.println("On Measure ::::: w=" + heightMeasureSpec + " h="
    + measureHeight(heightMeasureSpec));
 }

but if i override method by this code then i am getting only textbox view but i want both.pls help me

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  // TODO Auto-generated method stub
  System.out.println("On Measure ::::: w=" + widthMeasureSpec + " h="
    + heightMeasureSpec);
  System.out.println("On Measure ::::: w=" + getWidth() + " h="
    + getHeight());
  System.out.println("On Measure ::::: w=" + getWidth() + " h="
    + getHeight());
  // super.onMeasure(getWidth(), getHeight());
  setMeasuredDimension(getWidth(), SCREEN_HEIGHT);
  System.out.println("On Measure ::::: w=" + heightMeasureSpec + " h="
    + measureHeight(heightMeasureSpec));
 }