2011-11-22 73 views
1

嗨,我创建了一个CustomListField并实现了“drawListRow”方法在一行中绘制图像,文本和另一个图像。现在当我点击列表时,右侧的图像应该消失。 当我再次点击它应该再次出现的列表。这个怎么做。请发布代码。如何在黑莓中点击黑莓中的图片时显示和隐藏图片?

+1

您好,欢迎,我很遗憾地告诉你,我们没有“后的代码”。但是,如果您向我们提供您尝试过的产品,请告诉您可以修复或修复的内容。感谢您编辑您的帖子。 – Drahakar

+0

您可以用点击事件中的透明图像替换图像。 –

+0

你能告诉我怎么做。我是这个黑莓的新手。 – chaitu2408

回答

1

你将不得不跟踪哪些行被点击(因此有图像被隐藏),哪些没有。我会用一组布尔值来做到这一点。

重写CustomListField中的keyDown方法,并使用getSelectedIndex找出当前选中的行。

在您的drawListRow方法中请注意,ListField作为参数传递,将其转换回CustomListField并实现一个名为isRowClicked(int index)的新方法,该方法返回该行是否被点击,因此应该绘制带或不带右手图像。

代码大致如下:

public class CustomListField extends ListField implements ListFieldCallback{ 

    private static final int TOTAL_ROWS = 10; //total number of rows in list 
    private boolean[] clickedRows = new boolean[TOTAL_ROWS]; 

    public CustomListField(){ 
     //do all your instantiation stuff here 
    } 

    public boolean keyDown(int keycode, int time){ 

     int currentlySelectedRow = getSelectedIndex(); 

       //toggle the state of this row 
       clickedRows[currentlySelectedRow] = !clickedRows[currentlySelectedRow]; 

     //consume the click 
     return true; 
    } 

    public boolean isRowClicked(int index){ 
     return clickedRows[index]; 
    } 

    public void drawListRow(ListField listField, Graphics graphics, int index, 
     int y, int width) { 

     CustomListField customListfield = (CustomListField) listField; 

       //check whether this row is clicked 
       if(customListfield.isRowClicked(index)){ 

      //draw the state when the row is clicked 

     } else { 

      //draw the row when the row is not clicked 
     } 

    } 

} 
+0

嗨,我试过这个,但它不工作 – chaitu2408

+0

什么具体不工作?你有错误吗?请发布您的更新代码。 – donturner