Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
Posts: 14
Registered: ‎11-22-2008
My Device: 9360
My Carrier: T-Mobile CZ
Accepted Solution

click button for show ListField

Hello all,
please help... i don`t know where is problem Smiley Sad
I have two problems.
i have screen where is BasicEditField and ButtonField... if i want click to button so show me ListField.

 

here is my source code...

package com.screen;

import java.util.Vector;
import com.stepan.kutaj.bbmsearch.util.CustomListField;
import com.stepan.kutaj.bbmsearch.util.ListRander;
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.BasicEditField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;
import net.rim.device.api.ui.decor.BorderFactory;

public class Test extends MainScreen 
{
	private BasicEditField enterSearch;
	private ButtonField btnSearch;
	private String txtMenuAbout = "About";
	private Vector info = new Vector();
	private CustomListField myListView;
	private String Name;
	private Bitmap displayPicture = Bitmap.getBitmapResource("rounded.png");;

	public Test() 
	{
		super(MainScreen.VERTICAL_SCROLL | MainScreen.VERTICAL_SCROLLBAR);
		
		addMenuItem(_viewAboutMenu);

		this.getMainManager().setBackground(BackgroundFactory.createSolidBackground(0x00e5e5e5));

		Bitmap borderBitmap = Bitmap.getBitmapResource("rounded.png");
		
		VerticalFieldManager m = new VerticalFieldManager(MainScreen.NO_VERTICAL_SCROLL);
		m.setBorder(BorderFactory.createBitmapBorder(new XYEdges(12,12,12,12), borderBitmap));

		HorizontalFieldManager h = new HorizontalFieldManager(MainScreen.NO_VERTICAL_SCROLL);
		
		enterSearch = new BasicEditField("Search : ", "");
		btnSearch = new ButtonField("Search");
		btnSearch.setChangeListener(buttonListener);
		h.add(enterSearch);
		
		m.add(h);	
		add(m);
		add(btnSearch);
		
	}
	
	public boolean onClose() {
		System.exit(0);
		return true;
	}
	
	private MenuItem _viewAboutMenu = new MenuItem(txtMenuAbout, 10, 20)
	{
	   public void run() 
	   {
		   UiApplication.getUiApplication().pushScreen(new AboutScreen());
	   }
	};
	
	FieldChangeListener buttonListener = new FieldChangeListener() 
	{
		public void fieldChanged(Field field, int context) 
		{
			if (field == btnSearch) 
			{	
				Bitmap borderBitmap = Bitmap.getBitmapResource("rounded.png");
				VerticalFieldManager s = new VerticalFieldManager(MainScreen.NO_VERTICAL_SCROLL);
				s.setBorder(BorderFactory.createBitmapBorder(new XYEdges(12,12,12,12), borderBitmap));

					for(int in = 0; in < 4; in++)
					{
						Name = "Name" + in;
						
						String listTitle = Name;
						String listDesc = "Description: ";
						String listDesc2 = "Desc: ";

						info.addElement(new ListRander(displayPicture, listTitle, listDesc, listDesc2));
					}


				myListView = new CustomListField(info)
				{
					protected boolean trackwheelClick (int status, int time) 
					{
						Dialog.alert(" Selected :" + Name);
						return super.trackwheelClick(status, time);		
					}
				};
				
				s.add(myListView);
				add(s);
		    }
		}
	};
}

 and my problem is... when i click button that show me ListField and context menu... and i don`t know how disable open context menu... 

 

second problem is:
in this list i generated 4 rows with unique name

 

for(int in = 0; in < 4; in++)
{
Name = "Name" + in;
						
String listTitle = Name;
String listDesc = "Description: ";
String listDesc2 = "Desc: ";

info.addElement(new ListRander(displayPicture, listTitle, listDesc, listDesc2));
}

and i want click row so i need show name for this specific row...

 

myListView = new CustomListField(info)
{
    protected boolean trackwheelClick (int status, int time) 
    {
       Dialog.alert(" Selected :" + Name);
       return super.trackwheelClick(status, time);		
    }
};

 

and i have problem of course that show me every rows only last generated name (e.g name03).

can you help me please?

Thank you

Stepan

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: click button for show ListField

1) Change

btnSearch = new ButtonField("Search");

to

btnSearch = new ButtonField("Search", ButtonField.CONSUME_CLICK);

 

2) I would have thought that you want something like

    protected boolean trackwheelClick (int status, int time)
    {
ListRander selectedLine = (ListRander0 info.elementAt(this.getSekectedIndex());

String name = selectedLine.getName();

       Dialog.alert(" Selected :" + name);
       return super.trackwheelClick(status, time);
    }

Contributor
Posts: 14
Registered: ‎11-22-2008
My Device: 9360
My Carrier: T-Mobile CZ

Re: click button for show ListField

Hello Peter,

thank you very much... it`s function Smiley Happy

 

I changed it: 

 

protected boolean trackwheelClick (int status, int time) 
{
   ListRander selectedLine = (ListRander)info.elementAt(this.getSelectedIndex());
   String name = selectedLine.getListTitle();
   Dialog.alert(" Selected :" + name);
   return super.trackwheelClick(status, time); 
}

 

Thank you

 

Stepan

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: click button for show ListField

[ Edited ]

Good, please to hear this.

 

Forgot to add, I would recommend overriding navigationClick rather than trackwheelClick.  The trackwheel was used on older devices, it was a wheel on the righthandside.  navigationClick is used for the 'pearl' click and touchscreens will typically invoke this method if you have not processed the touch event 'CLICK in a touchEvent method.  Similarly if you don't have a navigationClick, then it will eventually invoke trackwheelClick. 

 

That said, if it ain't broke why fix it would suggest you leave the processing in trackwhewlClick. 

 

Cheers

Contributor
Posts: 14
Registered: ‎11-22-2008
My Device: 9360
My Carrier: T-Mobile CZ

Re: click button for show ListField

Thanks for information...
My application is only for device that have OS 5 and above (classic device with keyboard and with touch screen)... I think that device with OS 5 do not have wheel on the right side...

 

I should change trackwheelClick to navigationClick?

 

 

Cheers

 

p.s. sorry for my English

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: click button for show ListField

Your English is fine....

 

I think you are correct too, I am not aware of any devices running OS 5.0 that has a trackwheel.  In fact I am not aware of any devices with trackwheels that are running any OS later than OS 4.5.