リストフィールドアイテムをカスタマイズする方法
-
16-09-2020 - |
質問
BlackBerry Development.Myアプリケーションには、文字列を持つ5つのリスト項目が含まれています。 私はList項目のための1つの画像を一般的なビューのために2種類の画像を取った、そしてユーザーが以前よりも高さより高い高さのものをクリックしたときに選択されたアイテムを表示するためのものは1つです。
しかし問題は私が1つの項目を拡大して次の項目に重ね合わせていて、フル項目を表示していないと、それらの間でスペースを調整していない場合の問題です。 誰かが私にこれのための解決策を与えることができます。次のコードスニペットを使用しています....
_listField.setCallback(this);
_listField.setRowHeight(45);
_listField.setChangeListener(this);
.
パブリックボイドDrawListRow(ListField Arg0、Graphics Graphics、Int Index、 int y、int幅){
if (listFieldIndex != index) {
graphics.drawBitmap(0, y, listBkgrnd.getWidth(), listBkgrnd
.getHeight(), listBkgrnd, 0, 0);
graphics.setColor(0xAA0000);
graphics.setFont(this.getFont().derive(Font.BOLD, 17));
graphics.drawText(((Station) _stationList.elementAt(index))
.getStationName(), 15, y + 15, 0,
(listBkgrnd.getWidth() - 70));
graphics.setColor(0x770000);
graphics.setFont(this.getFont().derive(Font.PLAIN, 13));
// graphics.drawText(
// ((Station) _stationList.elementAt(index)).getCT(), 15,
// y + 40, 0, (listBkgrnd.getWidth() - 65));
} else {
graphics.drawBitmap(0, y, playBkgrnd.getWidth(), playBkgrnd
.getHeight(), playBkgrnd, 0, 0);
graphics.setColor(0xAA0000);
graphics.setFont(this.getFont().derive(Font.BOLD, 17));
graphics.drawText(((Station) _stationList.elementAt(index))
.getStationName(), 15, y + 15, 0,
(playBkgrnd.getWidth() - 70));
graphics.setColor(0x770000);
graphics.setFont(this.getFont().derive(Font.PLAIN, 13));
graphics.drawText(
s.getCT(), 15,
y + 40, 0, (playBkgrnd.getWidth() - 65));
}
}
. 解決
BlackBerryのリストフィールドは、すべての行が同じ高さであると想定しています。
欲しい効果の種類を取得するには、VerticalFieldManager
で選択可能なフィールドの束を使用してください。リストフィールドにも同様の効果が得られます。あなたのアイテムをフォーカシャブルにして、焦点を合わせたり失うときはいつでも、updateLayout
メソッドで、焦点が合ったかどうかに応じてフィールドの高さを設定してください。次の概要のようなもの:
public class CustomListFieldItem extends Field {
public boolean isFocusable() {
return true;
}
protected void onFocus(int direction) {
super.onFocus(direction);
updateLayout();
}
protected void onUnfocus() {
super.onUnfocus();
updateLayout();
}
protected void layout(int width, int height) {
if (isFocus()) {
setExtent(width, playBkgrnd.getHeight());
}
else {
setExtent(width, listBkgrnd.getHeight());
}
}
protected void paint(Graphics graphics) {
if (isFocus()) {
// draw selected item
}
else {
// draw unselected item
}
}
}
. 所属していません StackOverflow