Codenameone 当按钮位于列表单元格中时,如何处理该按钮

Codenameone 当按钮位于列表单元格中时,如何处理该按钮,codenameone,Codenameone,我有一个目标对象列表和一个类DestinationsRenderer,它扩展了容器并实现ListCellRenderer来呈现列表。列表中的每个单元格都有一个delete按钮,button类扩展button 我想做的是在按下delete按钮时突出显示其边框。我有两个主要问题: 按钮只有在按下和释放后才会做出反应,但我需要它在按下时做出反应,在释放时做出不同的动作 当我选择一个按钮时,列表中的所有按钮都会立即被选中 我用log语句验证了上面两个,但实际的边界甚至没有显示出来 我引用了之前回答的问题

我有一个目标对象列表和一个类DestinationsRenderer,它扩展了容器并实现ListCellRenderer来呈现列表。列表中的每个单元格都有一个delete按钮,button类扩展button

我想做的是在按下delete按钮时突出显示其边框。我有两个主要问题:

按钮只有在按下和释放后才会做出反应,但我需要它在按下时做出反应,在释放时做出不同的动作 当我选择一个按钮时,列表中的所有按钮都会立即被选中 我用log语句验证了上面两个,但实际的边界甚至没有显示出来 我引用了之前回答的问题,但这也没有解决第一个问题

列表操作侦听器是否可能被添加到错误的位置

以下是渲染器中的代码片段:

public DestinationsRenderer(final StateMachine stateMachine){

    // other code initializing the buttons and labels
    mDeleteButton.addActionListener(new ActionListener() {
            public void actionPerformed(final ActionEvent evt) {
                if (mList.getSelectedIndex() < mStateMachine.getNumDestinations()) {
                    mIsDeleteSelected = true;
                    mStateMachine.deleteDestination(mList.getSelectedIndex());
                }
            }
    }
}

public Component getListCellRendererComponent(final List list,
                                              final Object value,
                                              final int index,
                                              final boolean isSelected){
    // list of Destinations
    if(mList != null){
        mList.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt){
                if(mIsDeleteSelected){

                    mIsDeleteSelected = false;    // if i take out this line of code, 
                                                  // all of the buttons get highlighted 
                                                  // when i click, 
                                                  // but if i leave it in, none of them do
                    Style style = mDeleteButton.getPressedStyle();
                    style.setBorder(Border.createLineBorder(1, 1416152));
                    mDeleteButton.setPressedStyle(style);
                    mDeleteButton.setUnselectedStyle(style);
                    mDeleteButton.setSelectedStyle(style);
                    mDeleteButton.setDisabledStyle(style);
                } else {
                    Style style = mDeleteButton.getPressedStyle();
                    style.setBorder(Border.createEmpty());
                    mDeleteButton.setPressedStyle(style);
                    mDeleteButton.setUnselectedStyle(style);
                    mDeleteButton.setSelectedStyle(style);
                    mDeleteButton.setDisabledStyle(style);
                }
            }
        });
    }
    mList = list;
    // more code handling other list cell rendering stuff
}

正在不断调用GetListCellRenderComponent,如果将侦听器添加到该方法内的列表中,则将是一个错误。 我建议您将容器更改为长方体布局,而不是列表,这样可以更轻松地处理容器上的按钮和事件