2011-08-29 27 views
0

在我的應用程序中,我必須在列表字段中顯示項目列表,當我點擊列表字段中的特定項目時,特定行的背景顏色變爲灰色color.How開發此Blackberrry中的自定義列表字段的類型。任何一個請給點意見。如何在黑莓中開發自定義列表字段

謝謝你

回答

1

你應該在選定的listfield行中繪製矩形..有些事情是這樣的。在這裏,我已經做了的焦點..

public void drawListRow(ListField list, Graphics g, int index, int y,int w) { 

     if (g.isDrawingStyleSet(Graphics.DRAWSTYLE_FOCUS)) 
     { 
      g.setBackgroundColor(0x00572000); 
      //g.setBackgroundColor(); 
      g.clear(); 
      //g.setColor(Color.BLACK); 
      // g.fillRect(0,list.getWidth(),list.getWidth(),80); 
      g.setColor(Color.ORANGE); 
      g.fillRect(94,y+0,400,30); 
      //g.setColor(0x000000); 
      g.setColor(Color.WHITE); 
      g.drawText(text, 95, y+10, (DrawStyle.LEFT ), w); 
     } 
     else 
     { 
      g.setColor(0x00906966); 
      g.fillRect(94,y+0,400,30); 
      g.setColor(Color.ORANGE); 
      g.drawText(text, 95, y+10, (DrawStyle.LEFT ), w);  

     }} 
+0

謝謝你的答案。我測試了你的code.it顯示橙色,當一個列表項獲得焦點。如果我點擊該項目是否可以修復項目的橙色我點擊了 – Ajay

0

嘗試......

private class MyListField extends ListField{ 


//0,ListField.MULTI_SELECT 
    private boolean hasFocus = false; 

    public void onFocus(int direction){ 
    hasFocus = true;  
    } 

    public void onUnfocus() 
     { 
      hasFocus = false; 
      super.onUnfocus(); 
      invalidate(); 
     } 

    public void paint(Graphics graphics) 
     { int width = Display.getWidth(); 
      //Get the current clipping region 
      XYRect redrawRect = graphics.getClippingRect(); 
      if(redrawRect.y < 0) 
      { 
       throw new IllegalStateException("Error with clipping rect."); 
      } 

      //Determine the start location of the clipping region and end. 
      int rowHeight = getRowHeight(); 

      int curSelected; 

      //If the ListeField has focus determine the selected row. 
      if (hasFocus) 
      { 
       curSelected = getSelectedIndex(); 

      } 
      else 
      { 
       curSelected = -1; 
      } 

      int startLine = redrawRect.y/rowHeight; 
      int endLine = (redrawRect.y + redrawRect.height - 1)/rowHeight; 
      endLine = Math.min(endLine, getSize() - 1); 
      int y = startLine * rowHeight; 

      //Setup the data used for drawing. 
      int[] yInds = new int[]{y, y, y + rowHeight, y + rowHeight}; 
      int[] xInds = new int[]{0, width, width, 0}; 

      //Set the callback - assuming String values. 
      ListFieldCallback callBack = this.getCallback(); 

      //Draw each row 
      for(; startLine <= endLine; ++startLine) 
      {     
      //If the line we're drawing is the currentlySelected line then draw the fill path in LIGHTYELLOW and the 
      //font text in Black.  
      if(startLine == curSelected){ 

        graphics.setColor(Color.LIGHTYELLOW); 
        graphics.drawFilledPath(xInds, yInds, null, null); 
        graphics.setColor(Color.BLACK); 
        graphics.drawText((String)callBack.get(this, startLine), 0, yInds[0]); 

      } 
      else{ 
        //Draw the odd or selected rows. 
        graphics.setColor(Color.LIGHTGREY); 
        graphics.drawText((String)callBack.get(this, startLine), 0, yInds[0]); 
      } 

      //Assign new values to the y axis moving one row down. 
       y += rowHeight; 
       yInds[0] = y; 
       yInds[1] = yInds[0]; 
       yInds[2] = y + rowHeight; 
       yInds[3] = yInds[2]; 
      } 

      //super.paint(graphics); 
     } 
} 

。 。 。 參考這裏[LINK]:http://berrytutorials.blogspot.com/2009/11/create-custom-listfield-change.html