0

私はプログラムに取り組んでいます、とても簡単です。表示されたフィールドに人の名前を入力するだけです。[検索]をクリックすると、データベースが検索され、情報が取得されます。写真を含みます。これは問題なく動作しますが、1つの問題があります。peterを使用して検索を行い、データベースに2つの「peters」がある場合。スクロールすると。画像フィールドをクリックしない限り、画像は変更されません。私は関連するコードを投稿したと思います。どんな助けでもありがたいです。ありがとうございました

public class DriverSearchResultScreen extends MainScreen implements FieldChangeListener{
    LabelField header,title;

    LabelField lblLicenseNumber,lblFirstName,lblLastName,lblBirthDate,lblLicenseExpiry,lblLicenseType,lblLicenseStatus;

    ColoredMultiLineLabelField clblLicenseNumber,clblFirstName,clblLastName,clblBirthDate,clblLicenseExpiry,clblLicenseType,clblLicenseStatus;

    CustomButtonField btnSearch;

    CustomImageButton btnLeft,btnRight;

    CustomImageButton bmpfDriverPhoto;

    Vector licenseInfoData;

    int currentIndex = 0;

    public DriverSearchResultScreen(Vector licenseInfoData ) {

        this.licenseInfoData = licenseInfoData;
        // TODO Auto-generated constructor stub
        title = new LabelField("License",LabelField.USE_ALL_WIDTH);
        /*header.setBackground(bg);*/
        setTitle(title);

        bmpfDriverPhoto = new CustomImageButton(Bitmap.getBitmapResource("default-profile.png")){
            public boolean isFocusable() { return true; };
        };
        bmpfDriverPhoto.setChangeListener(this);
        add(bmpfDriverPhoto);

        header = new LabelField("",LabelField.FIELD_HCENTER|LabelField.USE_ALL_WIDTH){
                public void paint(Graphics g){
                    int col = g.getColor();
                    g.setColor(Color.YELLOW);
                    super.paint(g);
                    g.setColor(col);
                }
                public int getPreferredWidth(){
                    return net.rim.device.api.system.Display.getWidth();
                }
            };
        this.getMainManager().setBackground(BackgroundFactory.createBitmapBackground(Bitmap.getBitmapResource("background.png")));
        header.setFont(Font.getDefault().derive(Font.SANS_SERIF_STYLE|Font.BOLD,25));

        add(header);
        add(new SeparatorField());

        Bitmap vfmBackground = Bitmap.getBitmapResource("rounded-border.png");
        VerticalFieldManager vfm = new VerticalFieldManager();
        vfm.setBorder(BorderFactory.createBitmapBorder(new XYEdges(12,12,12,12),vfmBackground));

        BHorizontalFieldManager hfm = new BHorizontalFieldManager();
        lblFirstName= new LabelField("First Name :");
        hfm.add(lblFirstName);
        clblFirstName = new ColoredMultiLineLabelField("Jhon",Color.GRAY);
        hfm.add(clblFirstName);
        vfm.add(hfm);
        vfm.add(new SeparatorField());

        BHorizontalFieldManager hfm1 = new BHorizontalFieldManager();

        lblLastName= new LabelField("Last Name :");
        hfm1.add(lblLastName);
        clblLastName = new ColoredMultiLineLabelField("Doe",Color.GRAY);
        hfm1.add(clblLastName);
        vfm.add(hfm1);
        vfm.add(new SeparatorField());

        BHorizontalFieldManager hfm2 = new BHorizontalFieldManager();

        lblBirthDate = new LabelField("Date Of Birth:");
        hfm2.add(lblBirthDate);
        clblBirthDate = new ColoredMultiLineLabelField("11-June-1982",Color.GRAY);
        hfm2.add(clblBirthDate);
        vfm.add(hfm2);
        vfm.add(new SeparatorField());

        BHorizontalFieldManager hfm3 = new BHorizontalFieldManager();

        lblLicenseNumber = new LabelField("License Number :");
        hfm3.add(lblLicenseNumber);
        clblLicenseNumber = new ColoredMultiLineLabelField("999999",Color.GRAY);
        hfm3.add(clblLicenseNumber);
        vfm.add(hfm3);
        vfm.add(new SeparatorField());


        BHorizontalFieldManager hfm4 = new BHorizontalFieldManager();

        lblLicenseType = new LabelField("License Type :");
        hfm4.add(lblLicenseType);
        clblLicenseType = new ColoredMultiLineLabelField("B",Color.GRAY);
        hfm4.add(clblLicenseType);
        vfm.add(hfm4);
        vfm.add(new SeparatorField());


        BHorizontalFieldManager hfm5 = new BHorizontalFieldManager();

        lblLicenseExpiry = new LabelField("Expiry Date:");
        hfm5.add(lblLicenseExpiry);
        clblLicenseExpiry = new ColoredMultiLineLabelField("25-Aug-2012",Color.GRAY);
        hfm5.add(clblLicenseExpiry);
        vfm.add(hfm5);
        vfm.add(new SeparatorField());


        BHorizontalFieldManager hfm6 = new BHorizontalFieldManager();

        lblLicenseStatus = new LabelField("Licenes Status:");
        hfm6.add(lblLicenseStatus);
        clblLicenseStatus = new ColoredMultiLineLabelField("Expired",Color.GRAY);
        hfm6.add(clblLicenseStatus);
        vfm.add(hfm6);
        vfm.add(new SeparatorField());

        add(vfm);

        btnLeft = new CustomImageButton(Bitmap.getBitmapResource("left-arrow-enable.png"),Bitmap.getBitmapResource("left-arrow-disable.png"));
        btnRight= new CustomImageButton(Bitmap.getBitmapResource("right-arrow-enable.png"),Bitmap.getBitmapResource("right-arrow-disable.png"));;

        HorizontalFieldManager arrowButtonHfm = new HorizontalFieldManager(){

            public int getPreferredHeight() {
                // TODO Auto-generated method stub
                return btnLeft.getPreferredHeight()*2;
            }

            public int getPreferredWidth() {
                // TODO Auto-generated method stub
                return Display.getWidth();
            }

            protected void sublayout(int maxWidth, int maxHeight) {
                // TODO Auto-generated method stub
                int count = getFieldCount();
                for(int i = 0 ; i < count ; i++ ){
                    Field f = getField(i);

                    if(f == btnLeft ){
                        setPositionChild(f, (getPreferredWidth() >> 1) - f.getPreferredWidth() - 30, getPreferredHeight()>>1);
                    }else if (f == btnRight ){
                        setPositionChild(f, (getPreferredWidth() >> 1) + 30, getPreferredHeight()>>1);
                    }
                    layoutChild(f, getPreferredWidth(), getPreferredHeight());
                }
                setExtent(getPreferredWidth(),getPreferredHeight());
            }

            public void subpaint(Graphics graphics){
                int count = getFieldCount();
                for(int i = 0 ; i < count ; i++ ){
                    net.rim.device.api.ui.Field f = getField(i);
                    paintChild(graphics,f);
                }
            }

        };

        /*add(new LabelField(){
            public int getPreferredHeight() {
                return 10;
            }
         });*/
        btnLeft.setChangeListener(this);
        btnRight.setChangeListener(this);
        btnLeft.setEnabled(false);
        arrowButtonHfm.add(btnLeft);
        arrowButtonHfm.add(btnRight);
        add(arrowButtonHfm);
        fillLicenseHolderInfoToField((LicenseObject)licenseInfoData.elementAt(currentIndex));
        setHeaderText();
        enableDisableButtons();
    }

    private void setHeaderText(){
        header.setText("Search Results. ( "+(currentIndex+1)+ " of "+ (licenseInfoData.size())+" )");
    }


     private void fillLicenseHolderInfoToField(LicenseObject licenseObject){
        bmpfDriverPhoto.setImage(licenseObject.getBmpImage());
        clblLicenseNumber.setText(licenseObject.getLicenseNum());
        clblFirstName.setText(licenseObject.getFirstName());
        clblLastName.setText(licenseObject.getLastName());
        clblBirthDate.setText(licenseObject.getDateOfBirth());
        clblLicenseExpiry.setText(licenseObject.getDateOfExpiry());
        clblLicenseType.setText(licenseObject.getLicenseType());
        clblLicenseStatus.setText(licenseObject.getLicenseStatus());
    }

    public void fieldChanged(Field field, int context) {
        // TODO Auto-generated method stub
        if(field == btnRight){



            if( currentIndex < (licenseInfoData.size() - 1)){
                currentIndex++;
                fillLicenseHolderInfoToField((LicenseObject)licenseInfoData.elementAt(currentIndex));
            }
        }else if(field == btnLeft){
            if( currentIndex > 0 ){
                currentIndex--;
                fillLicenseHolderInfoToField((LicenseObject)licenseInfoData.elementAt(currentIndex));
            }
        }else if( field == bmpfDriverPhoto ){
            ImagePopDialog dialog = new ImagePopDialog("loader-image-box.png");
            Bitmap scaledBitmap = new Bitmap(300, 300);
            Bitmap btnBitmap    = bmpfDriverPhoto.getImage();
            btnBitmap.scaleInto(0, 0, btnBitmap.getWidth(), btnBitmap.getHeight(),
                        scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), 1);
            dialog.add(scaledBitmap);
            UiApplication.getUiApplication().pushScreen(dialog);

        }

        enableDisableButtons();
        setHeaderText();
    }


    private void enableDisableButtons(){
        btnLeft.setEnabled((currentIndex > 0)?true:false);
        btnRight.setEnabled((currentIndex < (licenseInfoData.size() - 1))?true:false);
    }
    protected boolean onSavePrompt() {
        // TODO Auto-generated method stub
        return true;
    }
}

//カスタム画像ボタン

package com.app.ui.component;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.TouchEvent;

/**
 * * 
 * Class to Draw an Image Button
 */
public class CustomImageButton extends Field {

/** Bitmap for enabled image */
private Bitmap bmpEnabled;

/** Bitmap for disabled image */
private Bitmap bmpDisabled;

/** Label for Button*/
private String label;

private boolean mEnabled=true;

private int mCurrentTouchX = 0;

private int mCurrentTouchY = 0;

/**
 * Constructor with
 * @param image
 */
public CustomImageButton(Bitmap image) {
    super(Field.FOCUSABLE);
    this.bmpEnabled = image;
}

/**
 * Constructor with
 * @param enabled
 * @param disabled
 */
public CustomImageButton(Bitmap enabled,Bitmap disabled) {
    this(enabled);
    this.bmpDisabled = disabled;
}

public CustomImageButton(Bitmap enabled, Bitmap disabled, String label) {
    this(enabled);
    this.bmpDisabled = disabled;
    this.label = label;
}

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

}

protected void paint(Graphics graphics) {
    if( isEnabled() ){
        if(isFocus()){
            int col = graphics.getColor();
            graphics.setColor(Color.WHITE);
            graphics.fillRect(0, 0, getPreferredHeight(), getPreferredHeight());
            graphics.setColor(col);
        }
        graphics.drawBitmap(5, 5, bmpEnabled.getWidth(), bmpEnabled.getHeight(), bmpEnabled,
            0, 0);          
        if(label != null && !label.equals("")) {
            graphics.setColor(Color.BLACK);
            graphics.drawText(label, bmpEnabled.getWidth()+5, (getPreferredHeight() - getFont().getHeight())/2);
        }
    }else{
        if( bmpDisabled != null )
            graphics.drawBitmap(5, 5, bmpDisabled.getWidth(), bmpDisabled.getHeight(), bmpDisabled,
                    0, 0);
        if(label != null && !label.equals("")) {
            graphics.setColor(Color.LIGHTGRAY);
            graphics.drawText(label, bmpEnabled.getWidth()+5, (getPreferredHeight() - getFont().getHeight())/2);
        }
    }
}

public int getPreferredWidth() {
    int prefwidth = 0;
    if(bmpEnabled != null) {    
        prefwidth =  bmpEnabled.getWidth(); 
    }   

    if(label != null && !label.equals("")) {    
        prefwidth = Display.getWidth()+10;
    }

    return (prefwidth+10);
}

public int getPreferredHeight() {
    if(bmpEnabled != null) {
        return bmpEnabled.getHeight()+10;
    }
    return 0;

}

/*protected boolean navigationClick(int status, int time) {
    fieldChangeNotify(0);
    return true;
}*/

/**
 * To set the focused background color and invalidating the entire screen
 */
protected void onFocus(int direction) {
    invalidate();
}

/**
 * To set the unfocused background color and invalidating the entire screen
 */
protected void onUnfocus() {
    invalidate();
}

/**
 * Draws the focus indicator for this field. 
 * @param graphics
 * @param on
 */
protected void drawFocus(Graphics graphics, boolean on) {
    super.drawFocus(graphics, on);
}

protected boolean navigationClick(int status, int time){
    if( mEnabled ){
        if (mCurrentTouchX >= 0 && mCurrentTouchX <= getPreferredWidth()
                && mCurrentTouchY >= 0
                && mCurrentTouchY <= getPreferredHeight())
            fieldChangeNotify(1);

        mCurrentTouchX = 0;
        mCurrentTouchY = 0;
        return true;
    }else{
        return false;
    }
}

protected boolean touchEvent(TouchEvent message) {
    if (mEnabled) {
        if (message.getEvent() == TouchEvent.CLICK) {
            mCurrentTouchX = message.getX(1);
            mCurrentTouchY = message.getY(1);
        }
    }
    return super.touchEvent(message);
}

public void setEnabled(boolean enabled) {
    // TODO Auto-generated method stub
    super.setEnabled(enabled);
    if(!enabled)
        this.focusRemove();
}

public void setImage(Bitmap image){
    this.bmpEnabled = image;
}

public Bitmap getImage(){
    return this.bmpEnabled;
}

}

4

1 に答える 1

0

CustomImageButtonクラスでは、setImageメソッドを変更する必要があります。

public void setImage(Bitmap image){
    this.bmpEnabled = image;
}

再描画を引き起こすために無効化を追加することによって:

public void setImage(Bitmap image){
    this.bmpEnabled = image;
    invalidate();
}

問題は、画像を置き換えると、画面が更新されるまで変更が画面に表示されないことです。invalidate()画面(またはレイアウト)の更新をトリガーし、更新を確認できるようにします。

画像をスクロールまたは選択するinvalidate()と、画面が更新されるときにメソッドが呼び出されるため、それまで更新されません。の手動トリガーは、invalidate()この問題を解決します。

イベントスレッドでそれを行っていることを確認してください。

于 2013-01-08T15:03:45.197 に答える