2011-11-22 1 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

관련 문제