Blackberry ObjectListField on click - blackberry

How to get selected row from blackberry objectlistfield, when user clicks on list item?

getSelectedIndex()
You will also have to set the setChangeListener() and implement the corresponding methods like fieldChanged() and keyDown()
have you read the documentation before asking ? Do you have a more specific question ?

public boolean navigationClick(int status, int time) {
Field focus = list.getLeafFieldWithFocus();
Dialog.alert("Focus String :: " + focus.getIndex());
if (focus instanceof ListField) {
ListField listField = (ListField)focus;
Dialog.alert("Selected Index"+listField.getSelectedIndex());
Dialog.alert("Selected List Value"+listField.getCallback().get(listField,
listField.getSelectedIndex()).toString());
}
return true;
}

Related

Move Focus is not working properly on List Field

I am working on ListView section, in this, the user can search the content by name and directly move at the first element of List via pressing a keyboard button. Like, if you press button B from (right vertical manager) it will scroll the list and move focus to first record of B.
The code is working fine in simulator but it's not working on Touch device - I have BB 9380 Curve.
here is the code for :
LabelField a = new LabelField("A" , FOCUSABLE)
{
protected void paint(Graphics graphics)
{
graphics.setColor(0xC4C4C4);
super.paint(graphics);
}
protected boolean navigationClick(int status, int time)
{
//fieldChangeNotify(1);
injectKey(Characters.LATIN_CAPITAL_LETTER_A);
injectKey(Characters.LATIN_CAPITAL_LETTER_A);
return true;
}
};
private void injectKey(char key)
{
try
{
searchList.setFocus();
KeyEvent inject = new KeyEvent(KeyEvent.KEY_DOWN, key, 0);
inject.post();
/*inject.post();*/
} catch (Exception e) {
Log.d("In injectKey :: :: :: "+e.toString());
MessageScreen.msgDialog("In Inject Key "+e.toString());
}
}
Alternate Solution
I would recommend a different strategy for this. Instead of trying to simulate key press events, I would define one method that handles a keypress of a certain letter, or a touch click on that same letter's LabelField.
Source: blackberry.com
So, you can have code that handles key presses by using
protected boolean keyChar( char character, int status, int time )
{
// you might only want to do this for the FIRST letter entered,
// but it sounds like you already have the keypress handling
// the way you want it ...
if( CharacterUtilities.isLetter(character) )
{
selectLetter(character);
return true;
}
return super.keyChar( character, status, time );
}
and then also handle touch events:
LabelField a = new LabelField("A" , FOCUSABLE)
{
protected void paint(Graphics graphics)
{
graphics.setColor(0xC4C4C4);
super.paint(graphics);
}
protected boolean navigationClick(int status, int time)
{
char letter = getText().charAt(0);
selectLetter(letter);
return true;
}
};
then, simply define a method that takes in one character, and scrolls to the start of that part of the list:
private void selectLetter(char letter);
Key Injection
If you really, really want to simulate key presses, though, you might try changing the code so that it injects two events: key down, and then key up (you're currently injecting two key down events). This might be causing problems.
injectKey(Characters.LATIN_CAPITAL_LETTER_A, true);
injectKey(Characters.LATIN_CAPITAL_LETTER_A, false);
with
private void injectKey(char key, boolean down)
{
try
{
searchList.setFocus();
int event = down ? KeyEvent.KEY_DOWN : KeyEvent.KEY_UP;
KeyEvent inject = new KeyEvent(event, key, 0);
inject.post();
} catch (Exception e) { /** code removed for clarity **/
}
}
Additional Note
For UIs, I like to trigger events on the key up, or unclick events. I think this makes a better experience for the user. So, you could replace keyChar() with keyUp() and navigationClick() with navigationUnclick() if you want to do this.

BB java objectchoicefiled should get display autmatically on selecting one value in other objectchoicefield i.e onchange functionality

Hi am trying to display objectchoicefield by set of data in array.by selecting that comparing with other array automatically another objectchoicefield should get display with corresponding matches.i.e, onchange function, the other objectchoicefield should get load with values.guide me.
Document document=generalXmlAccess.access(generalXmlAccess.getArea());
NodeList list2=document.getElementsByTagName("tuple");
final String[] area = new String [list2.getLength()];
final String[] areaid = new String [list2.getLength()];
for(int i=0;i<list2.getLength();i++)
{
NodeList list=document.getElementsByTagName("NAME");
NodeList list3=document.getElementsByTagName("ROW_ID");
area[i]=list.item(i).getFirstChild().toString()+"-"+list3.item(i).getFirstChild().toString();
areaid[i]=list3.item(i).getFirstChild().toString();
}
final ObjectChoiceField choiceField=new ObjectChoiceField("Select Area",area);
choiceField.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
if(field.equals(choiceField))
{
int index=choiceField.getSelectedIndex();
String values=areaid[index].toString();
Document document1=generalXmlAccess.access(generalXmlAccess.getSubArea());
NodeList list3=document1.getElementsByTagName("tuple");
for(int i=0;i<list3.getLength();i++)
{
subareaid=new String[list3.getLength()];
NodeList nodeList=document1.getElementsByTagName("PAR_ROW_ID");
if(nodeList.item(i).getFirstChild().toString().equals(values))
{
NodeList list=document1.getElementsByTagName("NAME");
subareaid[i]=list.item(i).getFirstChild().toString();
}
add(new ObjectChoiceField("Subarea", subareaid));
}
}
}
});
choiceField.setFont(font1);
I think, following steps might guide you.
Step 1: Create first objectchoicefield with its data.
Step 2: Implement its field change listener, in which you will use the selected value of first choicefield as parameter to get the array of corresponding values to be set to second objectchoicefield ..

how to show details when click on list filed?

Hi Friend's i want to show details when i click on this list field with image(location)means u take any lat long and show with it a image map.so please help me to solve this problem.
How is it possible please help me.
Thanks
on this link show the list field i am also create like this listfiled and when i click and show details with image map
How is it possible please help me.
Thanks
Here I am giving some example try this (assign index to each field in the list view). You can display your details in NewsScreen().
protected boolean navigationClick(int status, int time) {
int index;
System.out.println("CLICKED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
index = this.getFieldWithFocusIndex();
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run() {
UiApplication.getUiApplication().pushScreen(new NewsScreen());
}
});
System.out.println("OUTPUTTTTTTTTTTTTTTT"+this.getFieldWithFocusIndex());
return true;
}
you could pass the image map String URI or bitmap byte to the other screen and show it
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run() {
UiApplication.getUiApplication().pushScreen(new NewsScreen(IMAGE MAP STRING));
}
});

How search text in edit textfield in blackberry?

How can I handle event in EditText Field?.
Example: when I enter some text in EditText then what I have to do generate custom layout?
below is my screen.Does any one have idea please tell me.
try this
EditField text=new EditField()
{
protected boolean keyChar(char key, int status, int time)
{
if((int)key==10)//10 is ASCII code of "Enter" key
{
add(new LabelField("New Field"));
}
return super.keyChar(key, status, time);
}
};
add(text);
after enter all data just click on enter then new label will appear on screen

ObjectChoiceField in blackberry

In my application there is one ObjectChoiceField in MainScreen
i want to get change Listner of ObjectChoiceField after click on index 0.
i had already get click event of ObjectChoiceField after click on index grater than 1 and so on ..
so how can i get instance click event after click on ObjectChoiceField ?
I am not really sure what you are asking for.
In your FieldChangeListener.fieldChanged() method, calling ObjectChoiceField.getSelectedIndex() tells you which index is currently selected. You can look for index 0 from that.
If that is not what you need, then you need to clarify your question better.
ObjectChoiceField choiceField = new ObjectChoiceField();
public void fieldChanged(Field field, int context) {
if(field.equals(choiceField))
{
if(choiceField.getSelectedIndex==0)
{your Code}
}
If you want the value which the user have selected you can do by this way too
ObjectChoiceField choiceField = new ObjectChoiceField();
public void fieldChanged(Field field, int context) {
if(field.equals(choiceField))
{
if(choiceField.getSelectedIndex==0)
{
int index = choiceField.getSelectedIndex();
String s = (String) objectWeather.getChoice(index);
Dialog.inform("selected value is"+s);
}
}
}

Resources