Blackberry EditField - 高度改变无效
我尝试做的就是简单地更改 EditField 的高度。 这听起来很简单,但我面临着一个让我发疯的问题。 这是我的代码:
public class CMainManager extends HorizontalFieldManager
{
EditField mtxt=new EditField(EditField.FOCUSABLE | EditField.FILTER_DEFAULT);
/* Constructeur */
public CMainManager()
{
add(mtxt);
}
public int getPreferredHeight()
{
return Display.getHeight();
}
public int getPreferredWidth()
{
return Display.getWidth();
}
protected void sublayout(int width, int height)
{
layoutChild(mtxt, 50, 500);
setPositionChild(mtxt, 0, 10);
mtxt.setBackground(
BackgroundFactory.createSolidBackground(0x000000FF));
setExtent(width, height);
}
}
行layoutChild(mtxt, 50, 500);应该设置我的 EditField 的宽度和高度。确实如此,但仅限于宽度。高度是恒定的。如果我将其设置为 500,我会得到与将其设置为 10 相同的结果。
知道我缺少什么吗?因为我确信这是我正在做的一个愚蠢的错误...
谢谢
==编辑
在 jproffit 帮助之后,我明白了我做错了什么。然而现在它可以工作了(我可以设置高度)我有另一个问题。这是我的代码:
private EditField m_Txt=new EditField(EditField.FOCUSABLE |
EditField.FILTER_DEFAULT) {
protected void layout(int width, int height)
{
setExtent(Display.getWidth(), m_TxtHeight);
}
public boolean isFocusable()
{
return true;
}
protected void onFocus(int direction)
{
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
invalidate();
}
};
使用此代码我无法正确管理焦点。我忘记了什么?我在我的字段中看不到光标。
有什么想法吗?
谢谢
What I try to do is to simply change the height of an EditField.
This sounds pretty easy but I facing a problem that drives me crazy.
Here is my code:
public class CMainManager extends HorizontalFieldManager
{
EditField mtxt=new EditField(EditField.FOCUSABLE | EditField.FILTER_DEFAULT);
/* Constructeur */
public CMainManager()
{
add(mtxt);
}
public int getPreferredHeight()
{
return Display.getHeight();
}
public int getPreferredWidth()
{
return Display.getWidth();
}
protected void sublayout(int width, int height)
{
layoutChild(mtxt, 50, 500);
setPositionChild(mtxt, 0, 10);
mtxt.setBackground(
BackgroundFactory.createSolidBackground(0x000000FF));
setExtent(width, height);
}
}
The line layoutChild(mtxt, 50, 500); should set the width and height of my EditField. It does, but only with the width. The height is constant. If I set it to 500 I get the same result as if I set it to 10.
Any idea of what I'm missing ? because I'm sure this is a stupid error I'm doing...
Thanks
==edit
After jproffit help, I've understood what I did wrong. However now that it works (I can set the height) I have another problem. Here is me code:
private EditField m_Txt=new EditField(EditField.FOCUSABLE |
EditField.FILTER_DEFAULT) {
protected void layout(int width, int height)
{
setExtent(Display.getWidth(), m_TxtHeight);
}
public boolean isFocusable()
{
return true;
}
protected void onFocus(int direction)
{
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
super.onUnfocus();
invalidate();
}
};
With this code I cannot manage the focus correctly. What do I forget ? I cannot see the cursor in my field.
Any idea ?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不是告诉它要占用的尺寸,而是指定它可以占用的最大空间量。因此,当你告诉它 10、50 或 500 时,如果它只想使用 8 的高度,就这样。如果您还想控制 EditField 的尺寸,则必须重写 EditField 上的
layout()
。You aren't telling it the dimensions to take, you're specifying the maximum amount of space it can take up. So when you tell it 10, 50, or 500, if it only want to use a height of 8 that's all it will be. You'll have to override
layout()
on the EditField if you want to control its dimensions as well.尝试这样做..
创建自定义编辑字段并在布局方法内
Try doing like this..
create a custom editfield and inside the layout method