12-07-2010 07:57 AM
Hi All
How to load image from server one by one in to list field.
12-07-2010 08:04 AM
for Get Image from Web URL Look at below Thread
And For Put Image in the ListField Look at this Below thread
--------------------------------------------------
Press Kudo to say thank to developer.
Also Press the Accept as solution Button when u got the Solution.
12-07-2010 08:12 AM
Hey,
First you need to get data from server via web service.
Then you have to make one class which is having all field which ur web service have
Eg.
-<root>
−<employee>
<empno>1</empno>
<empname>abc</empname>
<empimage>http://abc.com/employee/images/NRA031B.jpg
</empimage>
</employee>
</root>
You need to fatch data from this webservice...
and set it to one of class
now getdata from class nd set it to bitmapfield
--------------------------------------------------
feel free to press the kudos button
on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
12-07-2010 08:25 AM
@ddgeek: absolutely no need to include a webservice in this usecase.
12-07-2010 10:09 AM
Exactly , you dont need a webservice.
i found this code in other tread:
private void downloadimage(String urlImage) {
HttpConnection connection = null;
InputStream inputStream = null;
EncodedImage _bmap;
byte[] dataArray = null;
Bitmap image=null;
for(int i=0;i<numberImages;i++){
try{
connection = (HttpConnection) Connector.open(urlImage,Connector.READ_WRITE, true);
inputStream = connection.openInputStream();
int length = 0;
byte[] responseData = new byte[10000];
StringBuffer rawResponse = new StringBuffer();
while (-1 != (length = inputStream.read(responseData))) {
rawResponse.append(new String(responseData, 0, length));
}
int responseCode = connection.getResponseCode();
if (responseCode != HttpConnection.HTTP_OK) {
throw new Exception("HTTP response code: " + responseCode);
}
final String result = rawResponse.toString();
dataArray = result.getBytes();
}
catch (final Exception ex) {
}
finally {
try {
inputStream.close();
inputStream = null;
connection.close();
} catch (Exception e) {
}
}// fin de Finally
_bmap = EncodedImage.createEncodedImage(dataArray, 0, dataArray.length);
image=_bmap.getBitmap();
}
ps: sorry for my english
12-09-2010 06:39 AM
hi ddgeek
This processes are working fine .i have more than 10 images in server, i need add image one by one in to listField. how is possible? if you have any sample code please send me it will be very help full.
Thanks in advance
12-09-2010 06:50 AM
12-09-2010 07:18 AM
I am going to write whole code of getting image file from server.
And set it to list field
-<root>
−<employee>
<empno>1</empno>
<empname>abc</empname>
<empimage>http://abc.com/employee/images/NRA031B.jpg
</empimage>
</employee>
</root>
Make one class:
public class Employee
{
public int id;
public String empname;
public String empimage;
public int getEmpid()
{
return empid;
}
public void setEmpid(int empid)
{
this.empid = empid;
}
public String getEmpname()
{
return empname;
}
public void setEmpname(String empname)
{
this.empname = empname;
}
public String getEmpimage()
{
return empimage;
}
public void setEmpimage(String empimage)
{
this.empimage = empimage;
}
}In your main class or screen you have to write these functions :
//get data from xml, set data to class set class to vector
public Vector getData()
{
// define variables later used for parsing
Document doc;
StreamConnection conn;
Employee e = null;
Vector vEmp = new Vector();
try
{
// providing the location of the XML file,
// your address might be different
String url = "http://abc.com/employee/getEmp";
if (DeviceInfo.isSimulator())
{
url = url + ";deviceSide=true";
}
conn = (StreamConnection) Connector.open(url);
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
docBuilder.isValidating();
doc = docBuilder.parse(conn.openInputStream());
doc.getDocumentElement().normalize();
NodeList list = doc.getElementsByTagName("category");
for (int i = 0; i < list.getLength(); i++)
{
e = new Employee();
Node item = list.item(i);
if (item.getNodeType() != Node.TEXT_NODE)
{
NodeList itemChilds = item.getChildNodes();
for (int j = 0; j < itemChilds.getLength(); j++)
{
Node detailNode = itemChilds.item(j);
if (detailNode.getNodeType() != Node.TEXT_NODE)
{
if (detailNode.getNodeName().equalsIgnoreCase("empno" ))
{
ctgr.setEmpid(Integer.parseInt(getNodeValue(detail Node)));
}
if (detailNode.getNodeName().equalsIgnoreCase("empnam e"))
{
ctgr.setEmpname(getNodeValue(detailNode));
}
if (detailNode.getNodeName().equalsIgnoreCase("empima ge"))
{
ctgr.setEmpimage(getNodeValue(detailNode));
}
}
}
}
vEmp.addElement(new Employee());
vEmp.setElementAt(e, i);
// v.addElement(e);
}
}// end try
// will catch any exception thrown by the XML parser
catch (Exception e)
{
System.out.println(e.toString());
}
return vEmp;
}
//get data from vector, set data to listfield
Vector getEmps = new Vector();
getEmps = getData();
BitmapField[] empImageField = null;
private Vector listInfoVector = new Vector();
private ListField empInfoListField;
for (i = 0; i < getItemDetails.size(); i++)
{
Employee emp = (Employee) getData.elementAt(i);
String imageURL = emp.getEmpimage();
String empName = item.getEmpname();
int empID = item.getEmpid();
LabelField empIDLabel = new LabelField(iname, Field.FIELD_LEFT);
LabelField empNameLabel = new LabelField(cname, FIELD_HCENTER);
Bitmap itemImageBitmap = null;
itemImageBitmap = getImageField(imageURL);
}
listInfoVector.addElement(new Info(empIDLabel, empNameLabel, itemImageBitmap));
empInfoListField = new ListField(listInfoVector.size()) {
//navigation click
};
empInfoListField.setCallback(this); // We manage the interaction!
this.add(empInfoListField);
public void drawListRow(ListField listField, Graphics g, int index, int y,
int width)
{
Info infoToDraw = (Info) this.get(listField, index);
g.drawText(infoToDraw.EmpNum, 90, y + 9);
g.drawText(infoToDraw.EmpName, Display.getWidth() - 90, y + 9);
// image of emp
g.drawBitmap(10, y + 6, 50, 50, infoToDraw.EmpImage, 0, 0);
g.drawLine(0, y, Display.getWidth(), y);
}
class Info
{
public LabelField EmpName;
public LabelField EmpNum;
public Bitmap EmpImage;
public Info(LabelField eName, LabelField eNum, Bitmap image)
{
EmpName = eName;
EmpNum = eNum;
EmpImage= image;
}
}
public BitmapField getImageField(String url) throws IOException
{
StreamConnection conn;
if (DeviceInfo.isSimulator())
{
url = url + ";deviceSide=true";
}
conn = (StreamConnection) Connector.open(url);
InputStream is = conn.openInputStream();
BitmapField bf = null;
try
{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int ch;
while ((ch = is.read()) != -1)
{
baos.write(ch);
}
byte imageData[] = baos.toByteArray();
bf = new BitmapField(EncodedImage.createEncodedImage(imageD ata, 0, imageData.length).getBitmap());
} finally
{
if (is != null)
{
is.close();
}
}
return (bf == null ? null : bf);
}
Full working example i provide you.
--------------------------------------------------
feel free to press the kudos button
on the left side to thank the user that helped you.
please mark posts as solved if you found a solution.
12-09-2010 07:31 AM
Hey ddgeek,
Its perfect solution.
I appreciate your work.
me: coolsmarty
12-09-2010 07:34 AM
hi simon
Thanks for the replay. actually i am newbie in blackberry, can you please brief it or send me the sample code if you have .
if you have any code sample link or something please feel free to provide me.
What i am doing in my code is
step1: Array of image URL
String [] urls={"http:/ipaddress/dev/cap.png",
"http://ipaddress/dev/Sweatshirt.png",
"http://ipaddress/dev/tshirt.png",
"http://ipaddress/dev/t-shirt.png",
"http://ipaddress/dev/youth_jersey.png"};
Step 2:
using "carlostheone's" code for loading the image display the bitmap, i got all the images from the server but it is taking so much time for displaying bitmaps.
What i need is
-------------------
First i want to display the listField which having Bitmap field
and want to display the bitmap one by one in the list field ...i guess this won't take too much of time ...
Thanks in advance