BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 09-12-2007, 03:56 AM   #1 (permalink)
New Member
 
Join Date: Sep 2007
Model: Pearl
PIN: N/A
Carrier: singtel
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default handling trackball click event on TreeField

Please Login to Remove!

Default implementation of TreeField is to use spacebar to expand and collape the tree node, i would appreciate if some can advice me how to expand and collapse the tree nodes on trackball click event. I tried with extending from TreeField and overriding public boolean navigationClick(int status, int time) method but it didnt work.

regards
prasad
Offline  
Old 09-12-2007, 04:12 AM   #2 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi prasad,

Override protected boolean trackwheelClick(int status, int time) to catch the trackwheel click event.

Cheers,
ARIF
Offline  
Old 09-13-2007, 01:02 AM   #3 (permalink)
New Member
 
Join Date: Sep 2007
Model: Pearl
PIN: N/A
Carrier: singtel
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Arif,
i tried with overriding protected boolean trackwheelClick(int status, int time) method as you reccomended as follows but it still didnt work. I would appreciate if you can correct the code (or) send me a sample code.


public class MyTreeField extends TreeField {



public MyTreeField(TreeFieldCallback callback, long style) {
super(callback, style);
}
private boolean selectAction() {

int currentNode = getCurrentNode();

if(getExpanded(currentNode))
setExpanded(currentNode,false);
else
setExpanded(currentNode,true);

return true;
}

protected boolean trackwheelClick(int status, int time) {
return selectAction();
}
}


Quote:
Originally Posted by arifzaman View Post
Hi prasad,

Override protected boolean trackwheelClick(int status, int time) to catch the trackwheel click event.

Cheers,
ARIF
Offline  
Old 09-13-2007, 01:48 AM   #4 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi prasad,

your code is absolutely OK. I've created TreeField instance on my screen and your code is working perfectly for me.

Code:
MyTreeField myTree = new MyTreeField(myCallback, TreeField.FOCUSABLE);
Let me know if your problem still exist! then i'll provide you my source class.

Cheers,
ARIF
Offline  
Old 09-13-2007, 02:19 AM   #5 (permalink)
New Member
 
Join Date: Sep 2007
Model: Pearl
PIN: N/A
Carrier: singtel
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Arif,
Even i added MyTreeFeild to my screen as follows

_treeField = new MyTreeField( this, Field.FOCUSABLE );
_treeField.setDefaultExpanded( false );
this.add( _treeField );

but once the treefield is displayed, if i click on the node it doesnt expand & collapse like when you use "space" button on tree node.
Please send me your working code.

regards
prasad


Quote:
Originally Posted by arifzaman View Post
Hi prasad,

your code is absolutely OK. I've created TreeField instance on my screen and your code is working perfectly for me.

Code:
MyTreeField myTree = new MyTreeField(myCallback, TreeField.FOCUSABLE);
Let me know if your problem still exist! then i'll provide you my source class.

Cheers,
ARIF
Offline  
Old 09-13-2007, 02:38 AM   #6 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by arifzaman View Post
Code:
MyTreeField myTree = new MyTreeField(myCallback, TreeField.FOCUSABLE);
Hi Arif, what kind of object is this "myCallback". As I saw this argument should be an instance implementing TreeFieldCallback interface. Where do you get it? And what is it for?
Offline  
Old 09-13-2007, 03:34 AM   #7 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi prasad,

Quote:
Originally Posted by sprasad View Post
Hi Arif,
Even i added MyTreeFeild to my screen as follows

_treeField = new MyTreeField( this, Field.FOCUSABLE );
_treeField.setDefaultExpanded( false );
this.add( _treeField );

but once the treefield is displayed, if i click on the node it doesnt expand & collapse like when you use "space" button on tree node.
Please send me your working code.

regards
prasad
Here is a simple example of TreeField:
Code:
import java.util.*;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;


final public class MyTreeFieldSample extends MainScreen {

    TreeCallback myCallback;
    TreeField myTree;

    public MyTreeFieldSample() {

        myCallback = new TreeCallback();

        myTree = new TreeField(myCallback, TreeField.FOCUSABLE) {
            private boolean selectAction() {
                int currentNode = getCurrentNode();
                if(getExpanded(currentNode))
                    setExpanded(currentNode,false);
                else
                    setExpanded(currentNode,true);
                return true;
            }

            protected boolean trackwheelClick(int status, int time) {
                return selectAction();
            }
         };
        int main1 = myTree.addChildNode(0, "MainItem1");
        int main2 = myTree.addChildNode(0, "MainItem2");
        int item1 = myTree.addChildNode(main1, "SubItem1");
        int item2 = myTree.addChildNode(main2, "SubItem2");
        int item3 = myTree.addChildNode(main2, "SubItem3");
        add(myTree);
    }

    public static class TreeCallback implements TreeFieldCallback
    {
        public void drawTreeItem(TreeField tree, Graphics g, int node,
            int y, int width, int indent) {

            Object obj = tree.getCookie(node);
            if (obj instanceof String) {
                String text = (String)obj;
                g.drawText(text, indent, y);
            }
        }
    }
}
Hope this will Help!

Cheers,
ARIF
Offline  
Old 09-13-2007, 03:35 AM   #8 (permalink)
Thumbs Must Hurt
 
Join Date: Jun 2007
Location: Bangladesh
Model: 8800
PIN: N/A
Carrier: EDGE
Posts: 93
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi pa4o85,

Quote:
Originally Posted by pa4o85 View Post
Hi Arif, what kind of object is this "myCallback". As I saw this argument should be an instance implementing TreeFieldCallback interface. Where do you get it? And what is it for?
Hope you'll get your answer from my previous reply!

Cheers,
ARIF
Offline  
Old 09-13-2007, 05:07 AM   #9 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by arifzaman View Post
Hi pa4o85,



Hope you'll get your answer from my previous reply!

Cheers,
ARIF
Definitely . Thank You!
Offline  
Old 09-13-2007, 05:08 AM   #10 (permalink)
New Member
 
Join Date: Sep 2007
Model: Pearl
PIN: N/A
Carrier: singtel
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks Arif,
your code is working fine and i dont see any difference between my code and your code . I will look into my project and correct the code.
Thanks a lot once again.

regards
prasad
Offline  
Old 03-25-2008, 08:32 AM   #11 (permalink)
Thumbs Must Hurt
 
Join Date: May 2007
Location: Bulgaria
Model: none
PIN: N/A
Carrier: Mtel
Posts: 150
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

How can i remove the "plus" and "minus" elements from the default tree field ?
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





Copyright 2004-2014 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.