首页 文章

选择问题(列表/多列表)codenameone

提问于
浏览
3

我做了以下操作来获取以watchVideo形式显示的列表中所选项目的json值...但是无论如何我都可以获取下一个列表项的值,以便我可以在watchVideo中设置下一个按钮形成并直接播放下一个视频......

findYoutubeMultiList(f).setModel(new com.codename1.ui.list.DefaultListModel(mData));
        findYoutubeMultiList(f).addActionListener((e) -> {
                    selection = (Map<String, String>) findYoutubeMultiList(f).getSelectedItem();
indexSelection = findYoutubeMultiList(f).getSelectedIndex();
**//i can get the index of selected item by above indexSelection but how to get the value of the incremented index??**
                    showForm("WatchVideo", null);
                });

编辑:

for (int i = 0; i < response.size(); i++) {
                        Hashtable hm = (Hashtable) response.get(i);
                        Hashtable snippet = (Hashtable) hm.get("snippet");
                        HashMap<String, Object> m = new HashMap<String, Object>();
                        videoResource = (Hashtable) snippet.get("resourceId");
                        videoId = videoResource.get("videoId").toString();
                        m.put("video", videoId);
                        mData.add(m);
                    }

WatchVideo表格:

protected void beforeWatchVideo(Form f) {

        for (int i = 0; i < mData.size(); i++) {
            //how to get the position of selection and more
 importantly how to get the values of incremented index
        }

1 回答

  • 1

    循环遍历多列表的源并获取所选项的索引,然后只需递增索引并获取该索引处的值,如果要播放前一个索引则减少 .

    请记住将索引与0和源长度进行比较以避免NullPointer .

相关问题