Blackberry ObjectChoiceField不显示下拉列表

时间:2012-08-30 13:54:46

标签: blackberry

ObjectChoiceField无法正常工作,因为下面的代码:

protected boolean navigationUnclick(int status, int time) {
    return true;
}

我添加了此代码以删除touchevent上的菜单。意味着我已经制作了自定义底部选项卡,并在屏幕上添加和删除垂直场。当我触摸任何Horizo​​ntalField时,它会显示菜单,这就是我添加上述代码的原因。

这是我的代码包含在水平字段中添加的ObjectChoiceField

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.EncodedImage;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.TouchEvent;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.container.VerticalFieldManager;

import com.ec.pleasewaitpopup.PleaseWaitPopupScreen;
import com.np.naijapings.ApplicationFont;
import com.np.naijapings.Constant;
import com.np.naijapings.TabControlScreen;
import com.np.naijapings.intermediateclasses.GetUserListIntermediator;
import com.tv.servercommunication.WebServiceDetails;

public class FindUsersScreen extends VerticalFieldManager implements FieldChangeListener{

    private VerticalFieldManager _mainVfm;
    private VerticalFieldManager _contentVfm;

    private BitmapField _headerBmp;
    private EncodedImage _bitmap;

    private LabelField _gender;
    private LabelField _age;
    private LabelField _religion;

    private ObjectChoiceField _genderChoiceField;
    private ObjectChoiceField _ageChoiceField;
    private ObjectChoiceField _religionChoiceField;

    private ButtonField _findUser;

    private static String[] _genderChoices={"Both gender","Male","Female"};
    private static String[] _ageChoices={"Any age","18-25","26-30","31-35","36-45","46-50"};
    private String[] _religionChoices={"Any religion","Hindu","Muslim"};

    public FindUsersScreen(){
        //HEADER IMG
        _bitmap = EncodedImage.
        getEncodedImageResource("find-user_header.png");
        _headerBmp = new BitmapField(Constant.sizePic(_bitmap, _bitmap.getHeight(), _bitmap.getWidth()));

        //MAIN VFM
        _mainVfm=new VerticalFieldManager();

        //CONTENT VFM
        final Bitmap tabBackGroundImage = Bitmap
        .getBitmapResource("finduserscr_bg.png");
        _contentVfm=new VerticalFieldManager(){
            protected void paint(Graphics graphics) {
                int y = FindUsersScreen.this.getManager().getVerticalScroll();
                graphics.drawBitmap( 0, y, tabBackGroundImage.getWidth(), tabBackGroundImage.getHeight(), tabBackGroundImage, 0, 0 );
                super.paint( graphics );
                }
        };

        //CREATE WIDGETS
        _gender=new LabelField("Gender");
        _genderChoiceField=new ObjectChoiceField("Gender", _genderChoices,0){
            protected boolean touchEvent(TouchEvent message) {

                return super.touchEvent(message);
            }
        };
        _age=new LabelField("Age");
        _ageChoiceField=new ObjectChoiceField("Age", _ageChoices,0);
        _religion=new LabelField("Religion");
        _religionChoiceField=new ObjectChoiceField("Religion", _religionChoices,0);
        _findUser=new ButtonField("    Find Users    ",ButtonField.CONSUME_CLICK);


        _findUser.setChangeListener(this);

        //SET FONT TYPE
        /*_gender.setFont(ApplicationFont.labelFont_16);
        _genderChoiceField.setFont(ApplicationFont.labelFont_16);
        _ageChoiceField.setFont(ApplicationFont.labelFont_16);
        _age.setFont(ApplicationFont.labelFont_20);
        _religionChoiceField.setFont(ApplicationFont.labelFont_20);
        _religion.setFont(ApplicationFont.labelFont_20);
*/
        //SET MARGIN
        /*_gender.setMargin(5,20,5,20);
        _age.setMargin(5,20,5,20);
        _religion.setMargin(5,20,5,20);
    */
        _contentVfm.setMargin(15,30,15,0);
        _genderChoiceField.setMargin(10,5,5,5);
        _religionChoiceField.setMargin(10,5,5,5);
        _ageChoiceField.setMargin(10,5,5,5);
        _findUser.setMargin(10,80,20,80);
        _contentVfm.setMargin(30,10,30,10);

        //ADD FIELDS TO CONTENT VFM
        //_contentVfm.add(_gender);
        _contentVfm.add(_genderChoiceField);
        //_contentVfm.add(_age);
        _contentVfm.add(_ageChoiceField);
        //_contentVfm.add(_religion);
        _contentVfm.add(_religionChoiceField);
        _contentVfm.add(_findUser);
        _mainVfm.add(_headerBmp);
        _mainVfm.add(_contentVfm);
        add(_mainVfm);
    }

    public void fieldChanged(Field field, int context) {
        if(field==_findUser){
            Object obAgeRange = _ageChoiceField.getChoice(_ageChoiceField.getSelectedIndex());
            String ageRange = obAgeRange.toString();

            Object obgender = _genderChoiceField.getChoice(_genderChoiceField.getSelectedIndex());
            String gender = obgender.toString();

            Object obReligion = _religionChoiceField.getChoice(_religionChoiceField.getSelectedIndex());
            String religion = obReligion.toString();

            GetUserListIntermediator getUserListIntermediator=new GetUserListIntermediator(ageRange,gender,religion);
            PleaseWaitPopupScreen.showScreenAndWait(getUserListIntermediator, Constant.PLEASE_WAIT_TEXT);
        }
    }

}

任何人都可以回答我如何解决这个问题。

1 个答案:

答案 0 :(得分:2)

您没有获得下拉列表,因为字段代码不处理unclick事件。在您的字段可以处理之前,您已截获并使用此事件(通过return true;)。

为您的事件处理程序试用此代码。

protected boolean navigationUnclick(int status, int time) {
        super.navigationUnclick(status, time);
        return true;
}