1

こんにちは、CustomListField を作成し、「drawListRow」メソッドを実装して、画像、テキスト、および別の画像を連続して描画しました。リストをクリックすると、右側の画像が消えるはずです。リストをもう一度クリックすると、再び表示されるはずです。これを行う方法。コードを投稿してください。

4

1 に答える 1

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
        }

    }

}
于 2011-11-22T23:31:42.927 に答える