누구든지 블랙 베리 5.0에 첨부 된 이미지와 유사한 사용자 정의 드롭 다운을 만들 수 있도록 도와주십시오. 나는 객체 선택 필드를 사용했지만 레이블과 함께오고있다. 사용자 생성 팝업 화면을 사용하여,검은 딸기에 사용자 정의 드롭 다운을 만드는 방법
답변
내 사용자 ChoiceField 만든 아래 이미지 쇼로 드롭 다운 나를 안내. 여기에 아래의 코드 샘플은
package com.src.java.rim.ui;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.DrawStyle;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.ListField;
import net.rim.device.api.ui.component.ListFieldCallback;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.PopupScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.Border;
import net.rim.device.api.ui.decor.BorderFactory;
public class FWCustomChoiceField extends HorizontalFieldManager {
/*space between text and icon*/
final int padding = 10;
String arrowBitmapName = "arrow_state_grey_right.png";
Object choice[] = null;
int index = -1;
String text = "Please select one option";
ListField choiceField = null;
public FWCustomChoiceField(final Object choice[]) {
this.choice = new Object[choice.length];
this.choice = choice;
choiceField = new ListField(){
protected boolean navigationClick(int status, int time) {
Field focus = UiApplication.getUiApplication().getActiveScreen() .getLeafFieldWithFocus();
if (focus instanceof ListField) {
ChoicePopupScreen popup = new ChoicePopupScreen(10, 80, choice);
popup.setChoice(choice);
UiApplication.getUiApplication().pushScreen(popup);
}
return super.navigationClick(status, time);
}
};
choiceField.setSize(1);
choiceField.setCallback(new TestListCallback());
add(choiceField);
}
public void setSelIndex(int index){
this.index = index;
this.text = choice[index].toString();
choiceField.invalidate();
}
public int getSelectedIndex(){
return index;
}
final class TestListCallback implements ListFieldCallback {
TestListCallback() {
}
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
Bitmap bitmap = Bitmap.getBitmapResource(arrowBitmapName);
int fontWidth = getFont().getAdvance(text);
int width = Display.getWidth() ;
int posX = (width-(fontWidth + padding + bitmap.getWidth()))/2;
int height = list.getRowHeight();
int posY = (height - bitmap.getHeight())/2;
g.drawText(text, posX, y, 0, w);
g.drawBitmap(posX+fontWidth+padding,posY, bitmap.getWidth(), bitmap.getHeight(), bitmap, 0, 0);
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return Graphics.getScreenWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
return listField.indexOfList(prefix, start);
}
}
public class ChoicePopupScreen extends PopupScreen {
Object []choice = null;
/*holds the position for popup screen*/
private int _posX = 0;
private int _posY = 0;
public ChoicePopupScreen(int posx,int posy, Object[] choice) {
/*calling super class constructor*/
super(new VerticalFieldManager(), Field.FOCUSABLE);
this.setMargin(new XYEdges(1,1,1,1));
this.choice = new Object[choice.length];
this.choice = choice;
/*Setting position for popup screen*/
_posX = posx;
_posY = posy;
/*list field customized to display as choice picker*/
ListField choiceList = new ListField(){
/*list field event handling using navigation click*/
protected boolean navigationClick(int status, int time) {
/*getting the selected list index value*/
int index = this.getSelectedIndex();
/*returning the selected index to the main field*/
setSelIndex(index);
/*removing the popup screen from the screen stack*/
UiApplication.getUiApplication().popScreen(UiApplication.getUiApplication().getActiveScreen());
/*required for event handling*/
return super.navigationClick(status, time);
}
};
/*displays the message when list is empty*/
choiceList.setEmptyString("List is empty", DrawStyle.LEFT);
choiceList.setSize(choice.length);
choiceList.setCallback(new PopUpListCallback());
add(choiceList);
Border border = BorderFactory.createSimpleBorder(new XYEdges(), Border.STYLE_TRANSPARENT);
this.setBorder(border);
}
protected void setChoice(Object []choice) {
this.choice = new Object[choice.length];
this.choice = choice;
}
protected void sublayout(int width, int height) {
super.sublayout(width, height);
/*setting the position for the popup screen*/
setPosition(_posX , _posY);
}
}
private class PopUpListCallback implements ListFieldCallback {
PopUpListCallback() {
}
public void drawListRow(ListField list, Graphics g, int index, int y, int w) {
String text = choice[index].toString();
g.drawText(text, padding, y, 0, w);
}
public Object get(ListField listField, int index) {
return null;
}
public int getPreferredWidth(ListField listField) {
return Graphics.getScreenWidth();
}
public int indexOfList(ListField listField, String prefix, int start) {
return listField.indexOfList(prefix, start);
}
}
}
위의 클래스를 사용하려면
String choicestrs[] = {"Opt 1", "Opt 2", "Opt 3"};
add(new FWCustomChoiceField(choicestrs));
알 겠어요.하지만 거기에 버그가 있습니다. 많은 목록이있는 경우 모든 항목을 스크롤 할 수 없습니다. –
@iDroidExplore는 코드 "super (new VerticalFieldManager (VERTICAL_SCROLL), Field.FOCUSABLE);" 스크롤 기능을위한 ChoicePopupScreen. –
@AnjaniJoshi 선택한 값을 얻는 방법? – Signare
- 1. 아래 드롭 다운을 만드는 방법
- 2. 검은 딸기에 열량을 계산하십시오
- 3. 검은 딸기에 HTTPpushdemo
- 4. 검은 딸기에 편집 필드를 사용자 정의하십시오
- 5. WPF Combobox의 드롭 다운을 만드는 방법 & 배치하기
- 6. 검은 딸기에 메뉴 항목을 제거하십시오
- 7. 검은 딸기에 http를 통해 비디오 스트리밍
- 8. sugarCRM 드롭 다운을 채우는 방법
- 9. Wordpress : 사용자가 날짜, 제목 또는 사용자 정의 필드별로 게시물을 정렬하는 드롭 다운을 만드는 방법
- 10. QTableView의 열에 드롭 다운을 표시하고 드롭 다운을 기반으로 필터하는 방법
- 11. 검은 딸기에 대한 자동 완성 검색 필드
- 12. 검은 딸기에 문자열 값 저장 문제
- 13. 검은 딸기에 진행 표시기가있는 스플래시 화면
- 14. 통합 이동 경로 드롭 다운을 생성하는 사용자 정의 메뉴 워커
- 15. Wordpress - 양식 제출에서 드롭 다운을 기반으로 맞춤 URL을 만드는 방법
- 16. mvc3의 드롭 다운을 채우려면
- 17. Rails에서 동적 드롭 다운을 만드는 방법은 무엇입니까?
- 18. 데이터베이스 생성 옵션으로 드롭 다운을 만드는 가장 쉬운 방법
- 19. PHP에서 지난 4 주간으로 채워진 드롭 다운을 만드는 방법
- 20. 드롭 다운을 기반으로 입력 필수 필드를 만드는 방법 선택 값
- 21. ActiveScaffold Rails 플러그인 (http://github.com/activescaffold)을 사용하여 사용자 정의 드롭 다운을 만드는 방법은 무엇입니까?
- 22. 메뉴에서 드롭 다운을 만드는 방법은 무엇입니까? Koala-Framework
- 23. 사용자 지정 Wordpress 테마에서 드롭 다운을 추가하십시오
- 24. android에서 사용자 정의 드롭 다운 메뉴를 만드는 방법
- 25. RoR 드릴 다운을 사용하여 양식을 만드는 방법
- 26. 내가 드롭 다운을 PHP로 디폴트 값을주고 싶습니다 드롭 다운을 PHP
- 27. 장고 관리자에서 고정 드롭 다운을 표시하는 방법?
- 28. 사용자 정의 jQuery 드롭 다운
- 29. 사용자 정의 html 컨트롤을 만드는 방법
- 30. 확인란을 선택하면 다른 드롭 다운을 기반으로 드롭 다운을 자동으로 선택합니다.
이 스레드 봐 난 당신이 유사 할 생각 http://supportforums.blackberry.com/t5/Java-Development/Custom-ObjectChoiseField/mp/341282 # M62571 – BBdev
레이블을 null로 설정할 수 있습니다. –