Share Pastebin
Guest
Public paste!

schwiz

By: a guest | Feb 9th, 2010 | Syntax: Java | Size: 1.91 KB | Hits: 121 | Expires: Never
Copy text to clipboard
  1. public class ItemList extends LinearLayout implements OnClickListener {
  2.  
  3.         public Rect outline;
  4.         LinkedList<Item> items;
  5.         WorkSheet gameRef;
  6.        
  7.         public ItemList(Context context, AttributeSet attrs) {
  8.                 super(context, attrs);
  9.                 gameRef = (WorkSheet) context;
  10.                 items = new LinkedList<Item>();
  11.                 //setOrientation(VERTICAL);
  12.  
  13.                
  14.         }
  15.        
  16.         @Override
  17.         protected void onSizeChanged(int w, int h, int oldw, int oldh) {
  18.                 // TODO Auto-generated method stub
  19.                 super.onSizeChanged(w, h, oldw, oldh);
  20.                 outline = rectFactory(2, 2, getWidth() -2 , getHeight() -2);
  21.  
  22.         }
  23.         @Override
  24.         public void onClick(View v) {
  25.                
  26.                 addItem("THIS is a test for my list");
  27.         }
  28.        
  29. //      @Override
  30. //      protected void onLayout(boolean changed, int l, int t, int r, int b) {
  31. //              // TODO Auto-generated method stub
  32. //              super.onLayout(changed, l, t, r, b);
  33. //              if(items != null){
  34. //                      for(int i = 0; i < items.size(); i++){
  35. //                              addViewInLayout(items.get(i), -1, items.get(i).getLayoutParams());
  36. //                      }
  37. //              }
  38. //      }
  39.        
  40.         void addItem(String desc){
  41.                 Item newItem = new Item(gameRef);
  42.                 newItem.setText(desc);
  43.                 newItem.setTextSize(13.0f);
  44.                 newItem.setTextColor(Color.BLACK);
  45.                 newItem.setBackgroundColor(Color.WHITE);
  46.                 newItem.setLayoutParams(new LayoutParams(outline.width() - 2, LayoutParams.WRAP_CONTENT));
  47.                 items.add(newItem);
  48.                 addView(newItem);
  49.         }
  50.        
  51.        
  52.         @Override
  53.         protected void onDraw(Canvas canvas) {
  54.                 canvas.drawRect(outline,Pallet.getInstance().blackOutline);
  55.                 super.onDraw(canvas);
  56.                
  57.         }      
  58.        
  59.         public Rect rectFactory(int x, int y, int width, int height){
  60.                 return new Rect(x,y,x+width-1, y+height-1);
  61.         }
  62.        
  63.        
  64.        
  65.        
  66.        
  67.        
  68.         private class Item extends TextView implements  OnLongClickListener{
  69.  
  70.                 public Item(Context context) {
  71.                         super(context);
  72.                         // TODO Auto-generated constructor stub
  73.                 }
  74.  
  75.                 @Override
  76.                 public boolean onLongClick(View v) {
  77.                         // TODO Auto-generated method stub
  78.                         return false;
  79.                 }
  80.                
  81.         }
  82. }