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
Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: FilePicker issues

I have tried that and I don't have exceptions @ all , its just that the the filepicker does not close after I select the image if the profile_pic.setBitmap(selected_bitmap) method is there so that's why I tried replacing the bitmapfield , which worked but the problem is the bitmapfield is the field that invokes the filepicker so after the first invocation and it replaces the bitmap the second time it is clicked it doesn't work , thanks
Developer
Posts: 132
Registered: ‎10-25-2011
My Device: Tour 9630
My Carrier: MTN

Re: FilePicker issues

i have finally found the solution  what i did was create a custom changelistener for the imagebuttonfield like this 

class ImageButtonListener implements FieldChangeListener
{

public void fieldChanged(Field field, int context)
{
// TODO Auto-generated method stub
if(field instanceof ImageButtonField)
{
try
{
UiApplication.getUiApplication().invokeLater(new Runnable()
{


public void run()
{
// TODO Auto-generated method stub
FilePicker filePicker = FilePicker.getInstance();
filePicker.setPath(getSelectedPhotoPath());
filePicker.setListener(new FilePickListener());
filePicker.show();



// ImageButtonField bf = new ImageButtonField(bmp, Field.FIELD_VCENTER);
// profile_pic.setBitmap(bmp);
/** synchronized (UiApplication.getEventLock()) {
profile_pic.setBitmap(bmp);
invalidate();
}**/

//profile_container.deleteAll();
// profile_container.add(new ImageButtonField(bmp, Field.FIELD_VCENTER));




}
});
}
catch(Throwable e)
{
Dialog.alert("Unexpected Error "+ e.getMessage());
}
}

}

}

 

and then i added this listener to my initial profile_pic object in my constructor  like this  

profile_pic.setChangeListener(new ImageButtonListener());

 

then the next thing i did was to perfect my filepicklistener  listener class like this 

/**
*
* class for filepicker listener
* @author insolsoft-lab
*
*/
class FilePickListener implements FilePicker.Listener
{
public void selectionDone(String path) //invoked when user has selected a file
{
Bitmap bmp = getTheImage(path);

profile_container.deleteAll();
// profile_pic.setBitmap(bmp);
ImageButtonField bmf = new ImageButtonField(bmp, Field.FIELD_VCENTER);
bmf.setChangeListener( new ImageButtonListener());

profile_container.add(bmf);
invalidate();





}
}

and it worked very  well . the question is why do i need to change the bitmapfield for each change and add my lsitener to it each time , well it works , it goes out to all the people that ight face the same problem , your thougths peter might help in perfecting it , thanks a whole lot .