标签上的字段更改侦听器
我正在从 json url 检索对象列表,并通过添加标签字段和分隔符将其显示为列表。现在,我想让每个标签可点击,以便每个标签重定向到单独的网址。单击标签后,必须打开一个单独的屏幕,其中包含相应 url 的 json 数据。那么,谁能告诉我如何实现这一目标。如果我得到一些如何做到这一点的示例代码,我将非常感激...这是我已经完成的一些示例代码...
public VerticalFieldManager showShoppingList(){
try {
jsArrShpList=new JSONArray(strShopping);
totalList= jsArrShpList.length();
for(int i=0;i<totalList;i++){
String strAlert=jsArrShpList.get(i).toString();
JSONObject joAlert=new JSONObject(strAlert);
String shoppingList = joAlert.get("CategoryName").toString();
LabelField shops = new LabelField(shoppingList);
VerticalFieldManager vfmListRow=new VerticalFieldManager();
vfmListRow.add(shops);
vfmListRow.add(new SeparatorField());
vfmShpList.add(vfmListRow);
}
return vfmShpList;
I am retrieving a list of objects from json url and displaying it like a list by adding a label field and a seperator. Now, i want to make each label clickable so that each label redirects to a seperate url. On clicking the label a seperate screen must open with the json data of the corresponding url. So, can anyone tell me how to achieve this. I wil be really grateful if i get some sample code of how to do it... Here's some sample code that i have done...
public VerticalFieldManager showShoppingList(){
try {
jsArrShpList=new JSONArray(strShopping);
totalList= jsArrShpList.length();
for(int i=0;i<totalList;i++){
String strAlert=jsArrShpList.get(i).toString();
JSONObject joAlert=new JSONObject(strAlert);
String shoppingList = joAlert.get("CategoryName").toString();
LabelField shops = new LabelField(shoppingList);
VerticalFieldManager vfmListRow=new VerticalFieldManager();
vfmListRow.add(shops);
vfmListRow.add(new SeparatorField());
vfmShpList.add(vfmListRow);
}
return vfmShpList;
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与其使用一堆通常不接受焦点或单击事件的 LabelField,为什么不使用 ListField 在屏幕上?这似乎更符合您的要求。
如果您确实想采用 LabelField 方法,则需要执行一些操作。首先,当您创建 LabelField 时,请使用
Field.FOCUSABLE
样式,以便它接受焦点:现在,由于 LabelField 字段不会调用更改监听器(如果您设置了一个),因此您'需要在其父管理器中监听单击和按键事件。由于这些单击或按键事件可以针对管理器中的任何字段,因此您需要在事件发生时检查哪个字段处于焦点状态,并根据焦点字段运行任何适当的处理程序。
代码示例:
Instead of using a bunch of LabelFields which don't normally accept focus or click events, why not use a ListField on the screen? That seems to be more of what you're looking for.
If you do want to go with the LabelField approach, you'll need to do a few things. First, when you create your LabelField, use the
Field.FOCUSABLE
style so that it will accept focus:Now, since the LabelField field won't call into a change listener if you set one up, you'll need to listen for click and key events in it's parent manager. Since these click or key events can be for any field in the manager, you need to check which field is in focus when the event occurs, and run any appropriate handler based on the field in focus.
Code example: