i am new to blackberry and do not know much about it. I am learning and implementing list having too many sections/headers.For that i have implemented so far:
here is my code:
public class MyScreen extends MainScreen
{
/**
* Creates a new MyScreen object
*/
public MyScreen()
{
super(Manager.NO_VERTICAL_SCROLL);
setTitle("Simple List Demo");
add(new LabelField("A"));
add(new SeparatorField());
Manager mainManager = getMainManager();
SimpleList listField = new SimpleList(mainManager);
listField.add("Item 1");
listField.add("Item 2");
listField.add("Item 3");
add(new SeparatorField());
add(new LabelField("B"));
add(new SeparatorField());
SimpleList list=new SimpleList(mainManager);
list.add("Item 4");
list.add("Item 5");
list.add("Item 6");
add(new SeparatorField());
}
}
I want to implement as:
Can anybody share the idea how to implement this sort of listfield.I have taken two listfields and added separatorField,labelfield to distinguish but this is not the way as this would be too tedious to implement and maintain too many lists.Any help would be appreciated.
Thanks in advance.
Akash
It is not one ListField instance on the screen. There are several ListField instances separated by LabelField instances.
Just add combinations of LabelField and ListField instances to the one screen.
Related
I have written code to attach a fieldchange listener to a button.The issue is that i want this button centered.I know the code to center a button. The issue is to get code to both center the button and include a fieldchange listener to it. Here are some code snippets:
FieldChangeListener listener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
ButtonField register = (ButtonField) field;
UiApplication.getUiApplication().pushScreen(new Register());
}
};
ButtonField register = new ButtonField("Register",ButtonField.CONSUME_CLICK);
register.setChangeListener(listener);
add(register);
How can i center this button?
I put two and two together and came up with this:
FieldChangeListener listener = new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
ButtonField register = (ButtonField) field;
UiApplication.getUiApplication().pushScreen(new Register());
}
};
ButtonField menu = new ButtonField("Menu", Field.FIELD_HCENTER);
add(menu);
add(new LabelField("New User?",Field.FIELD_HCENTER));
ButtonField register = new ButtonField("Register",ButtonField.CONSUME_CLICK|Field.FIELD_HCENTER);
register.setChangeListener(listener);
add(register);
This piece of code:
ButtonField.CONSUME_CLICK|Field.FIELD_HCENTER
Is what does the trick
After loading the screen If i click on the button directly, the setChangeListener event is not being invoked, rather when the focus is changed to button/hfm, the setChangeListener event is getting called and the desired result is also obtained.
What might be the possible reason and please help me fix this issue...
HorizontalFieldManager hfm = new HorizontalFieldManager();
ButtonField buttonF = new ButtonField(ButtonField.CONSUME_CLICK);
buttonF.setLabel("View Key");
FieldChangeListener listeneronClick = new FieldChangeListener()
{
public void fieldChanged(Field field, int context)
{
System.out.println("in fieldchange");
ButtonField buttononClick = (ButtonField) field;
buttononClick.setLabel("Hide Key");
}
};
hfm.add(buttonF);
buttonF.setChangeListener(listeneronClick);
Thanks in advance.
Try creating your button like the following
ButtonField button = new ButtonField("Ok", ButtonField.CONSUME_CLICK);
ButtonField.CONSUME_CLICK Indicates to the button consume the click event.
Your FieldChangeListener won't do anything because it creates a new button and does not add it to the screen. I'm guessing you just want to change the text on your existing button so try the following code:
HorizontalFieldManager hfm = new HorizontalFieldManager();
final ButtonField buttonF = new ButtonField(ButtonField.CONSUME_CLICK);
buttonF.setLabel("View Key");
FieldChangeListener listeneronClick = new FieldChangeListener(){
public void fieldChanged(Field field, int context)
{
System.out.println("in fieldchange");
buttonF.setLabel("Hide Key");
}
};
hfm.add(buttonF);
buttonF.setChangeListener(listeneronClick);
try calling hfm.setFocus() before adding hfm to the screen manager.
I have a verticalfieldmanager with buttons and below that a browserfield. The problem is that when I scroll vertically in the browserfield the whole layout of the app scrolls with it(!).. I've been looking like a mad man for a sollution but haven't found anything yet. I tried disabling vertical scroll in the app but this only results in not being able to scroll the browserfield/homepage.
Any suggestions?
Thanks
Hope this code helps you: try this;
public class NewsBrowserScreen extends MainScreen implements FieldChangeListener
{
String url="http://www.google.com/news/";
VerticalFieldManager vertical;
BrowserField browserField;
ButtonField click;
public NewsBrowserScreen()
{
createGUI();
}
private void createGUI()
{
click=new ButtonField("Click",Field.FIELD_HCENTER);
click.setChangeListener(this);
add(click);
vertical=new VerticalFieldManager(VERTICAL_SCROLL|VERTICAL_SCROLLBAR|HORIZONTAL_SCROLL|HORIZONTAL_SCROLLBAR)
{
protected void sublayout(int maxWidth, int maxHeight)
{
super.sublayout(Display.getWidth(),250);
setExtent(Display.getWidth(),250);
}
};
vertical.setBackground(BackgroundFactory.createSolidBackground(Color.GREEN));
vertical.setPadding(10, 0, 10, 0);
add(vertical);
}
protected boolean onSavePrompt()
{
return true;
}
public boolean onMenu(int instance)
{
return true;
}
public void fieldChanged(Field field, int context)
{
if(field==click)
{
browserField=new BrowserField();
vertical.add(browserField);
browserField.requestContent(url);
}
}
}
I Get like this below Image;
You can add a VerticalFieldManager to your MainScreen and add your BrowserField to your VerticalFieldManager. You should set style of VerticalFieldManager with VERTICAL_SCROLL | VERTICAL_SCROLLBAR and clear the syle of your MainScreen
How to add click event in blackberry banner ad.
Here is my code:
public class DemonstrationScreen extends MainScreen
{
public DemonstrationScreen()
{
final Bitmap customPlaceholder = Bitmap.getBitmapResource("arrow.png");
Banner bannerAd = new Banner(add.APID,null,10000, customPlaceholder);
bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
VerticalFieldManager vfm = new VerticalFieldManager
(VerticalFieldManager.NO_VERTICAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLLBAR
| VerticalFieldManager.USE_ALL_WIDTH);
HorizontalFieldManager hfm = new HorizontalFieldManager
(HorizontalFieldManager.FIELD_HCENTER
| HorizontalFieldManager.FIELD_VCENTER);
hfm.add(bannerAd);
vfm.add(hfm);
add(vfm);
FieldChangeListener listener=new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if(field==bannerAd){
Dialog.alert("Banner clicked");
}
}};
bannerAd.setChangeListener(listener);
}
}
this is not working. when i click the ad, then its not showing anythig.
I do think this is unexpected/improper usage of Banner.
However you could potentially do this by overriding navigationClick() at Banner:
public class DemonstrationScreen extends MainScreen
{
public DemonstrationScreen()
{
final Bitmap customPlaceholder = Bitmap.getBitmapResource("arrow.png");
Banner bannerAd = new Banner(add.APID,null,10000, customPlaceholder) {
protected boolean navigationClick(int status, int time) {
Dialog.alert("Banner clicked");
return super.navigationClick(status, time);
}
};
bannerAd.setMMASize(Banner.MMA_SIZE_EXTRA_LARGE);
VerticalFieldManager vfm = new VerticalFieldManager
(VerticalFieldManager.NO_VERTICAL_SCROLL
| VerticalFieldManager.NO_VERTICAL_SCROLLBAR
| VerticalFieldManager.USE_ALL_WIDTH);
HorizontalFieldManager hfm = new HorizontalFieldManager
(HorizontalFieldManager.FIELD_HCENTER
| HorizontalFieldManager.FIELD_VCENTER);
hfm.add(bannerAd);
vfm.add(hfm);
add(vfm);
}
}
But since RIM made Banner class final you can not do this. So I think your request has no simple solution. A hard solution would be to "figure out" what field is clicked at the MainScreen level (in navigationClick of MainScreen you can check what field is in focus and do smth).
I wrote an app which has 2 screens. The first screen is triggered by the main class. The second screen is opened by clicking a button in the first screen.
public class MyApp extends UiApplication{
public static void main(String[] args){
MyApp theApp = new MyApp();
theApp.enterEventDispatcher();
}
public MyApp(){
// Push a screen onto the UI stack for rendering.
pushScreen(new MyScreen());
}
}
public class MyScreen extends MainScreen implements FieldChangeListener
{
BasicEditField mEdit = null;
ButtonField mButton = null;
public MyScreen()
{
super();
mEdit = new BasicEditField("input: ", "some text");
add(mEdit);
mButton = new ButtonField("Go second screen");
mButton.setChangeListener(this);
add(mButton);
}
public void fieldChanged(Field field, int context)
{
if(mButton == field)
{
MyScreen2 scr = new MyScreen2();
scr.setTextValue(mEdit.getText());
UiApplication.getUiApplication().pushScreen(scr);
UiApplication.getUiApplication().popScreen(this);
}
}
}
public final class MyScreen2 extends MainScreen
{
String mTextValue = null;
LabelField mLabel = null;
public void setTextValue(String textValue)
{
mTextValue = textValue;
mLabel.setText(mTextValue);
}
public MyScreen2()
{
super();
mLabel = new LabelField();
add(mLabel);
}
}
It works on the 9700 simulator, but doesn't work on the smartphone. I wonder what is wrong? I wonder if the smartphone blocks loading app from my computer?
I tried signing .cod but nothing changes.
Any idea?
you need signing key to run your application on real device ... It cost near about 20 dollars
go here
you can find all the details from here
I think it might help you
cheers