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
New Developer
Posts: 47
Registered: ‎05-11-2012
My Device: Blackberry Bold 9930
My Carrier: Tmobile

Aligning Question!

Hi,

I have a question about aligning a data that I parsed using Json. I used this example in my code

 

http://stackoverflow.com/questions/9544158/json-parsing-in-blackberry-5-0

 

The parsed Id and name always shows in the top right side of the screen. I tried to use a horizontalfieldmanager (it worked but only to align the id horizontally) which I need but I also need to move the id to the middle of the screen. I tried the gridfieldmanager but I failed to make it work.

 

Thank you for reading my message.

 

Waiting for your help.

 

Thanks

Developer
Posts: 228
Registered: ‎10-01-2011
My Device: Passport

Re: Aligning Question!

You'll need to provide more informaiton, the sample you gave has no alignment statements at all and the JSON you are downloading has no tab characters in it which i suspected would be the issue.

New Developer
Posts: 47
Registered: ‎05-11-2012
My Device: Blackberry Bold 9930
My Carrier: Tmobile

Re: Aligning Question!

[ Edited ]

Thank you for your response. 

Here is the code I'm using to alignment 

 

With gridfield (it only change the color and the font the background color ..etc ) I can't move it . 

 

GridFieldManager gridFieldManager = new GridFieldManager(2,0);

String to =j.getString("USERNAME");

gridFieldManager.add(new CustomLabelField("Welcome " + to+ "!", Color.WHITE, Color.GOLDENROD,Field.FIELD_VCENTER));

add(gridFieldManager);

 

---------------------------------------------------------------------------------------

With Horizontalfield manager (with this I can move it to the middle of the screen)

 

HorizontalFieldManager iCenter = new HorizontalFieldManager(Field.FIELD_HCENTER);

iCenter.add(new LabelField("Welcome "+to + "!"));
add(iCenter);

 

 

What do you mean by the JSON i'm using? Do you mean the code? or the JOSN library? 

 

Thank you so much.

 

 

this is the JSON method that i'm using 

 

public void parseJSONResponceInBB(String jsonInStrFormat)
{


try {
JSONObject json = new JSONObject(jsonInStrFormat);
JSONArray jArray= json.getJSONArray("userinfo");

//JSONArray arr=jArray.getJSONArray(0);

for(int i=0;i<jArray.length();i++)
{
JSONObject j = jArray.getJSONObject(i);


String from = j.getString("USERID");
// add(new LabelField("id=="+from));

HorizontalFieldManager iCenter = new HorizontalFieldManager(Field.FIELD_HCENTER);
GridFieldManager gridFieldManager = new GridFieldManager(2,0);

String to =j.getString("USERNAME");

gridFieldManager.add(new CustomLabelField("Welcome " + to+ "!", Color.WHITE, Color.GOLDENROD,Field.FIELD_VCENTER));


add(gridFieldManager);




//String to =j.getString("USERNAME");
/*iCenter.add(new LabelField("Welcome "+to +" "+from+ "!"));
add(iCenter);*/

}
} catch (JSONException e)
{
e.printStackTrace();
}

 

}

New Developer
Posts: 47
Registered: ‎05-11-2012
My Device: Blackberry Bold 9930
My Carrier: Tmobile

Re: Aligning Question!

Thank you so much again. Problem solved. 

 

I've used a forgroundmanager in my code and I didn't add it to the parsing code. 

 

Sorry to bother you. Thank you again.