我正在检索JSON URL中的对象列表,并通过添加标签字段和一个Semperator来像列表一样显示它。现在,我想使每个标签可单击,以使每个标签都重定向到单独的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;
有帮助吗?

解决方案

而不是使用一堆通常不接受焦点或单击事件的Labelfields,为什么不使用 ListField 屏幕上?这似乎更多是您想要的。

如果您想采用Labelfield方法,则需要做一些事情。首先,当您创建Labelfield时,请使用 Field.FOCUSABLE 风格,以便它可以接受重点:

LabelField shops  = new LabelField(shoppingList, Field.FOCUSABLE);

现在,由于Labelfield字段将不会在设置一个侦听器中呼叫侦听器,因此您需要在其父母经理中收听单击和密钥事件。由于这些单击或密钥事件可以用于管理器中的任何字段,因此您需要在事件发生时检查哪个字段,并根据焦点中的字段运行任何适当的处理程序。

代码示例:

VerticalFieldManager vfmListRow = new VerticalFieldManager() {
    protected boolean navigationClick(int status, int time) {
        Field field = getFieldWithFocus();
        if (field != null && field.equals(shops)) {
            System.out.println("shops field clicked");
            return true;
        }
        return super.navigationClick(status, time);
    }

    protected boolean keyChar(char key, int status, int time) {
        Field field = getFieldWithFocus();
        if (key == Characters.ENTER && field != null && field.equals(shops)) {
            System.out.println("shops field clicked");
            return true;
        }
        return super.keyChar(key, status, time);
    }
};
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top