2011-12-21 17 views
0

正しいルートを使用しているかどうかはわかりませんが、カスタムフィールドを作成しverticalfieldmanagerで使用することに決めました。Blackberry:VerticalFieldManagerで使用するカスタムフィールドを作成してテーブルビューを複製する

カスタムフィールドでは、左側に画像を追加し、右側にテキストを追加します。

私はまだ始まったばかりですが、いくつかの問題にぶつかりました。

package mypackage; 

import net.rim.device.api.ui.DrawStyle; 
import net.rim.device.api.ui.Field; 
import net.rim.device.api.ui.Graphics; 

public class CustomEventField extends Field implements DrawStyle { 

    private String title; 
    private String by; 
    private String date; 
    private String desc; 


    public CustomEventField(String title, String by, String date, String desc){ 
     super(); 
     this.title = title; 
     this.by = by; 
     this.date = date; 
     this.desc = desc; 

    } 

    protected void layout(int width, int height) { 
     setExtent(width,height); 

    } 

    protected void paint(Graphics graphics) { 

     graphics.drawText(this.title, 0, 0); 

     graphics.drawText(this.by, 50, 0); 


    } 

} 

drawTextの前にdrawTextから次の行に移動するにはどうすればよいですか?フォントの高さを計算し、それをyの位置に追加する必要がありますか?

+0

賭けを、次のような出力が得られます –

答えて

2

上記のコードによれば、画像、タイトル、日付を表示できるカスタムクラスを1つ作成しました。あなたがアイテムをクリックすると、1つのダイアログが、これはまた、カスタムリストビュー

注意するのに便利ですそのインデックス番号 で表示されます:あなたはここに利用できる。この次の画像を試してみたい場合は、ちょうどこのPLease download sample images from here

ここでもしあれば修正を使用します私は

class CustomListField extends HorizontalFieldManager{ 

     private Bitmap scale_image; 
     private int width=0; 
     private int height=0; 
     private int background_color=0; 
     private BitmapField bitmap_field; 
     private boolean flag=false; 
     public CustomListField(String title, Bitmap image, String date,int image_width,int image_height,int background_color){ 
      super(NO_HORIZONTAL_SCROLL|USE_ALL_WIDTH); 
      this.background_color=background_color; 
      width=image_width; 
      height=image_width; 
      if(image!=null){ 
       scale_image=new Bitmap(image_width, image_height); 
       image.scaleInto(scale_image, Bitmap.FILTER_LANCZOS); 
       bitmap_field=new BitmapField(scale_image); 
       flag=false; 
       bitmap_field.setMargin(5, 5, 5, 5); 
       add(bitmap_field); 
      } 


      VerticalFieldManager vmanager=new VerticalFieldManager(USE_ALL_WIDTH|Field.FIELD_VCENTER){ 
       protected void sublayout(int maxWidth, int maxHeight) { 
        super.sublayout(Display.getWidth()-width, height); 
        setExtent(Display.getWidth()-width, height); 
       } 
      }; 
      LabelField title_lbl=new LabelField("Title: "+title,Field.NON_FOCUSABLE|DrawStyle.ELLIPSIS); 
      vmanager.add(title_lbl); 

      LabelField date_lbl=new LabelField("Date: "+date,Field.NON_FOCUSABLE); 
      vmanager.add(date_lbl); 

      Font fon=title_lbl.getFont(); 
      int title_height=fon.getHeight(); 

      Font font=date_lbl.getFont(); 
      int date_height=font.getHeight(); 
      int pad=title_height+date_height; 
      title_lbl.setPadding((height-pad)/2, 0, 0, 0); 
      add(vmanager); 
      add(new NullField(FOCUSABLE)); 
     } 

     protected void sublayout(int maxWidth, int maxHeight) { 
      super.sublayout(Display.getWidth(), height); 
      setExtent(Display.getWidth(), height); 
     } 
     protected void paint(Graphics graphics) { 
      if(flag) 
      graphics.setBackgroundColor(background_color); 
      graphics.clear(); 
      super.paint(graphics); 
     } 
     protected void onFocus(int direction) { 
      super.onFocus(direction); 
      flag=true; 
      invalidate(); 
     } 
     protected void onUnfocus() { 
      invalidate(); 
      flag=false; 
     } 
     protected boolean navigationClick(int status, int time) { 

      if(Touchscreen.isSupported()){ 
       return false; 
      }else{ 
       fieldChangeNotify(1); 
       return true; 
      } 

     } 
     protected boolean touchEvent(TouchEvent message) 
     { 
      if (TouchEvent.CLICK == message.getEvent()) 
      { 

       FieldChangeListener listener = getChangeListener(); 
       if (null != listener) 
        this.setFocus(); 
        listener.fieldChanged(this, 1); 
      } 
      return super.touchEvent(message); 
     } 
    } 

はあなたがビットマップ、タイトル、IMAGE_HEIGHTと幅を渡す必要があり、次の方法として、このクラスを呼び出すことができます知っている、と背景clolorください

 class sampleScreen extends MainScreen implements FieldChangeListener 
     { 
      private CustomListField cu_field[]; 
      private Bitmap image=null; 
      int size=8; 
      public sampleScreen() { 
       VerticalFieldManager vmanager=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR){ 
        protected void sublayout(int maxWidth, int maxHeight) { 

         super.sublayout(Display.getWidth(),Display.getHeight()); 
         setExtent(Display.getWidth(),Display.getHeight()); 
        } 
       }; 
       cu_field=new CustomListField[size]; 
       for(int i=0;i<size;i++){ 
        image=Bitmap.getBitmapResource("sample_"+i+".jpg"); 
cu_field[i]=new CustomListField("BlackBerry models that had a built-in mobile phone, were the first models that natively ran Java, and transmitted data over the normal 2G cellular network. RIM began to advertise these devices as email-capable mobile phones rather than as 2-way pagers.", 
    image, "jan2011", 100, 100,Color.RED); 
        cu_field[i].setChangeListener(this); 
        vmanager.add(new SeparatorField()); 
        vmanager.add(cu_field[i]); 
       } 
       add(vmanager); 
      } 

      public void fieldChanged(Field field, int context) { 
       // TODO Auto-generated method stub 
       for(int i=0;i<size;i++){ 
        if(field==cu_field[i]){ 
         final int k=i; 
         UiApplication.getUiApplication().invokeLater(new Runnable() { 
          public void run() { 
           Dialog.alert("You click on Item No "+k); 
          } 
         }); 
        } 
       } 
      } 
     } 

ここでは、私たちが理解できるイメージとしてあなたの条件を挿入し、あなたを助けるためにしようとする画像

This is out put for above code

関連する問題