Blackberry:检测长按 ListField 并显示菜单
如何检测 ListField 组件上的长按?
您是否重写其 navigationClick(int status, int time) 并摸索其 time 参数(如何?),或者是否有一些内置方法来检测长时间点击?
更重要的是 - 一旦检测到这样的点击,如何显示菜单(屏幕中间的菜单)?
背景是,通过短暂的点击,我想让用户编辑所选的项目。长按时我想在屏幕中间显示一个菜单以提供辅助任务:删除项目、更改项目显示顺序等。
下面是我当前的测试代码 - src\mypackage\MyList.java :
package mypackage;
import java.util.*;
import net.rim.device.api.collection.*;
import net.rim.device.api.collection.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.util.*;
public class MyList extends UiApplication {
public static void main(String args[]) {
MyList app = new MyList();
app.enterEventDispatcher();
}
public MyList() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen {
ObjectListField myList = new ObjectListField() {
protected boolean navigationClick(int status, int time) {
System.err.println("XXX status=" + status + ", index=" + getSelectedIndex());
return true;
}
};
public MyScreen() {
setTitle("How to detect long click?");
myList.set(new String[] { "Item 1", "Item 2", "Item 3", "Item 4", });
add(myList);
}
}
谢谢 亚历克斯
How do you detect a long click on a ListField component?
Do you override its navigationClick(int status, int time) and fumble with its time argument (how?) or is there some builtin method for detecting long clicks?
And more importantly - how do you display the menu (the one in the middle of the screen) once you detected such a click?
The background is that on short clicks I'd like to let the user edit the selected item. And on long clicks I'd like to display a menu in the middle of the screen to offer secondary tasks: delete item, change item display order, etc.
Below is my current test code - src\mypackage\MyList.java:
package mypackage;
import java.util.*;
import net.rim.device.api.collection.*;
import net.rim.device.api.collection.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.ui.decor.*;
import net.rim.device.api.util.*;
public class MyList extends UiApplication {
public static void main(String args[]) {
MyList app = new MyList();
app.enterEventDispatcher();
}
public MyList() {
pushScreen(new MyScreen());
}
}
class MyScreen extends MainScreen {
ObjectListField myList = new ObjectListField() {
protected boolean navigationClick(int status, int time) {
System.err.println("XXX status=" + status + ", index=" + getSelectedIndex());
return true;
}
};
public MyScreen() {
setTitle("How to detect long click?");
myList.set(new String[] { "Item 1", "Item 2", "Item 3", "Item 4", });
add(myList);
}
}
Thank you
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以覆盖
touchEvent
字段的方法。然后做这样的事情:请注意,这是一个粗略的实现,只是为了给您一个想法。我这里只使用了时间坐标。您的实现可能需要考虑用户触摸屏幕位置的 X 和 Y 坐标,因为如果他移动手指,那么就不是触摸并按住。
You can override the
touchEvent
method of your Field. Then do something like this:Please note that this is a rough implementation just to give you an idea. I only used the time coordinate here. Your implementation will probably need to factor in the X and Y coordinates of where the user touched the screen, because if he moved his finger, then that wouldn't be a touch and hold.