在黑莓AutoCompleteField占位符文本 [英] Place holder text on a AutoCompleteField in blackberry

查看:110
本文介绍了在黑莓AutoCompleteField占位符文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经TP在我的黑莓应用程序屏幕的一个地方 AutoCompleteField 。我必须表现出占位符的文本,为用户输入的信息提供线索。

I have tp place a AutoCompleteField in one of my screen in Blackberry app. I have to show a place holder text to provide hint for user to enter the information.

下面是 AutoCompleteField

BasicFilteredList filterList = new BasicFilteredList();
        String[] address = { "T 115 Centro Galleria Shopping Centre, Cnr Old Collier and Walters Road Morley WA 1522", 
                "1423 SEAVIEW POINT POINT COOK VIC 2674",
                "Lot 1498 Yarraman Road Wyndham Vale VIC 3795", 
                "Lot 3506 Witchmount Close Hillside VIC 4055",
                "6 Paas Place Williamstown VIC 4233", 
                "Lot 99 14 James Close Sunbury VIC 4502", 
                "1 Charlotte Street Clayton South VIC 4779" };

        filterList.addDataSet(1, address, "address", BasicFilteredList.COMPARISON_IGNORE_CASE);
        AutoCompleteField autoCompleteField = new AutoCompleteField(filterList){
            public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) {
                 ListField _list = getListField();
                 if (_list.getSelectedIndex() > -1) {
                     if(selectedText!=null){
                         BasicFilteredListResult result = (BasicFilteredListResult) selection;
                         selectedText.setText(result._object.toString());
                     }
                 }
             }
        };
        add(autoCompleteField);

任何人,请建议我怎么能实现相同。

Anyone, please suggest me how could I implement the same.

感谢。

推荐答案

您可以使用类似的技术来这里显示正常之一EditFields 。基本上,你需要重写的油漆中的 AutoCompleteField 子类()方法。在的paint(),你检查,看看是否该字段为空,如果是这样,你手工绘制的占位符的你想要的文字。

You can use a similar technique to the one shown here for normal EditFields. Basically, you need to override the paint() method in an AutoCompleteField subclass. In paint(), you check and see if the field is empty, and if so, you manually draw the placeholder text you want.

不同的是, AutoCompleteField 管理​​ BasicEditField 里面它。因此,要正确绘制文本,你需要在父弄清楚编辑字段的x和y偏移管理​​(即 AutoCompleteField )。

The difference is that AutoCompleteField is a Manager with a BasicEditField inside of it. So, to draw the text properly, you need to figure out the x and y offsets of the edit field within the parent Manager (the AutoCompleteField).

所以,这个类的一个实例来替换你的 AutoCompleteField 实例:

So, replace your AutoCompleteField instance with an instance of this class:

   private class CustomAutoCompleteField extends AutoCompleteField {
      private int yOffset = 0;
      private int xOffset = 0;

      public CustomAutoCompleteField(BasicFilteredList filteredList) {
         super(filteredList);
      }

      protected void paint(Graphics g) {
         super.paint(g);
         if (xOffset == 0) {
            // initialize text offsets once
            xOffset = getEditField().getContentLeft();
            yOffset = getEditField().getContentTop();
         }
         String text = getEditField().getText();
         if (text == null || text.length() == 0) {
            int oldColor = g.getColor();
            g.setColor(Color.GRAY);
            g.drawText("enter text", xOffset, yOffset);
            g.setColor(oldColor);
         }
      }

      public void onSelect(Object selection, int SELECT_TRACKWHEEL_CLICK) {
         ListField _list = getListField();
         if (_list.getSelectedIndex() > -1) {
            if(selectedText!=null){
               BasicFilteredListResult result = (BasicFilteredListResult) selection;
               selectedText.setText(result._object.toString());
            }
         }
      }
   }

我测试的OS 5.0,与没有任何保证金或填充集的实例。这有可能是与不同​​的布局,你可能需要调整的逻辑计算x和y偏移。但是,上述code说明你的基本理念。祝你好运。

I tested this on OS 5.0, with an instance that didn't have any margin or padding set. It's possible that with different layouts, you may need to adjust the logic for calculating the x and y offsets. But, the above code shows you the basic idea. Good luck.

编辑:以上code是需要提醒的是你的 ONSELECT()方法显然是依赖于$ psented $ P code未显示。由于是,上述code将无法编译。我离开 ONSELECT()在那里只是为了表明我基本上只是代替你原本匿名类,并没有做任何事情在不同的 ONSELECT()方法,因为它没有直接关系的占位符文本的问题。

the above code is presented with the caveat that your onSelect() method is clearly relying on code not shown. As is, the above code won't compile. I left onSelect() in there just to show that I'm essentially just replacing the anonymous class you originally had, and not doing anything different in your onSelect() method, as it's not directly related to the placeholder text issue.

这篇关于在黑莓AutoCompleteField占位符文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆