×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    Need help populating a choice group from a record store.

    I'm trying to populate a choice group from a record store.

    First, I write three strings to the record store.

    Then I use a loop to read the strings into a string buffer.

    From that string buffer, I make a new string.

    From that string, I use String[] to make another string.

    I then use that latter string in a choice group.

    Instead of the choice group having three choices, there is only one choice.

    I would like the choice group to look like the below:

    Choice A
    Choice B
    Choice C
    Instead, the choice group looks like this:

    "Choice A", "Choice B", "Choice C"
    Below is an excerpt from the code:

    Code:
    			// Write to the record store.
    			String strTestString = "Choice A";
    			byte[] bytesTesting = strTestString.getBytes();
    			
    			try {
                    testDb.addRecord(bytesTesting, 0, bytesTesting.length);
                } 
    			catch (RecordStoreException e) {
    				e.printStackTrace();
                }
    
    			// Write to the record store a second time.
    			String strTestString2 = "Choice B";
    			byte[] bytesTesting2 = strTestString2.getBytes();
    			
    			try {
                    testDb.addRecord(bytesTesting2, 0, bytesTesting2.length);
                } 
    			catch (RecordStoreException e) {
    				e.printStackTrace();
                }
    
    			// Write to the record store a third time.
    			String strTestString3 = "Choice C";
    			byte[] bytesTesting3 = strTestString3.getBytes();
    			
    			try {
                    testDb.addRecord(bytesTesting3, 0, bytesTesting3.length);
                } 
    			catch (RecordStoreException e) {
    				e.printStackTrace();
                }
    
    			strbBuffer = new StringBuffer();
    
    			// Read from the record store.
    			try {
    				intNumberOfRecords = testDb.getNumRecords();
    			} catch (RecordStoreNotOpenException ex) {
    				ex.printStackTrace();
    			}
    			for (int j = 1; j <= intNumberOfRecords; j++) {
    				byte b[] = null;
    					try {
    						b = testDb.getRecord(j);
    					} catch (RecordStoreException rse) {
    						rse.printStackTrace();
    					}
    				str = new String(b,0,b.length);
    				if (j == 1) {
    					strbBuffer.append("\"");
    				}
    				strbBuffer.append(str);
    				if (j != intNumberOfRecords) {
    					strbBuffer.append("\", \"");
    				} else {
    					strbBuffer.append("\"");
    				}
    				screen.append(str);
    				screen.append("\n");
    			}
    			
    			String strMixedTogetherString = new String(strbBuffer.toString());
    			screen.append(strMixedTogetherString);
    			// The below commented-out line produces the output that I am seeking.
    			//String[] strChoices = { "Choice A", "Choice B", "Choice C" };
    			// The below line of code does not produce the output that I am seeking.
    			String[] strChoices = { strMixedTogetherString };
    			ChoiceGroup cgChoices = new ChoiceGroup("Select one or more", List.MULTIPLE, strChoices, null);
    			screen.append(cgChoices);

    Any help that could be provided would be greatly appreciated.

  2. #2
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    Smile Re: Need help populating a choice group from a record store.

    I think that I found the answer by searching the Internet using the below keywords:

    j2me populating a choice group from a record store
    By inserting this line of code just above the last line of the code excerpt in my previous message post, I was able to generate two choices in the choice group:

    Code:
    cgReceiptCategoryChoices.append(strMixedTogetherString, null);
    Now, I will edit the code some more, so as to obtain the three choices.

  3. #3
    Regular Contributor
    Join Date
    Mar 2011
    Location
    Pune,Maharashtra,India
    Posts
    92

    Re: Need help populating a choice group from a record store.

    Quote Originally Posted by John_123 View Post
    I'm trying to populate a choice group from a record store.

    First, I write three strings to the record store.

    Then I use a loop to read the strings into a string buffer.

    From that string buffer, I make a new string.

    From that string, I use String[] to make another string.

    I then use that latter string in a choice group.

    Instead of the choice group having three choices, there is only one choice.

    I would like the choice group to look like the below:



    Instead, the choice group looks like this:



    Below is an excerpt from the code:

    Code:
    			// Write to the record store.
    			String strTestString = "Choice A";
    			byte[] bytesTesting = strTestString.getBytes();
    			
    			try {
                    testDb.addRecord(bytesTesting, 0, bytesTesting.length);
                } 
    			catch (RecordStoreException e) {
    				e.printStackTrace();
                }
    
    			// Write to the record store a second time.
    			String strTestString2 = "Choice B";
    			byte[] bytesTesting2 = strTestString2.getBytes();
    			
    			try {
                    testDb.addRecord(bytesTesting2, 0, bytesTesting2.length);
                } 
    			catch (RecordStoreException e) {
    				e.printStackTrace();
                }
    
    			// Write to the record store a third time.
    			String strTestString3 = "Choice C";
    			byte[] bytesTesting3 = strTestString3.getBytes();
    			
    			try {
                    testDb.addRecord(bytesTesting3, 0, bytesTesting3.length);
                } 
    			catch (RecordStoreException e) {
    				e.printStackTrace();
                }
    
    			strbBuffer = new StringBuffer();
    
    			// Read from the record store.
    			try {
    				intNumberOfRecords = testDb.getNumRecords();
    			} catch (RecordStoreNotOpenException ex) {
    				ex.printStackTrace();
    			}
    			for (int j = 1; j <= intNumberOfRecords; j++) {
    				byte b[] = null;
    					try {
    						b = testDb.getRecord(j);
    					} catch (RecordStoreException rse) {
    						rse.printStackTrace();
    					}
    				str = new String(b,0,b.length);
    				if (j == 1) {
    					strbBuffer.append("\"");
    				}
    				strbBuffer.append(str);
    				if (j != intNumberOfRecords) {
    					strbBuffer.append("\", \"");
    				} else {
    					strbBuffer.append("\"");
    				}
    				screen.append(str);
    				screen.append("\n");
    			}
    			
    			String strMixedTogetherString = new String(strbBuffer.toString());
    			screen.append(strMixedTogetherString);
    			// The below commented-out line produces the output that I am seeking.
    			//String[] strChoices = { "Choice A", "Choice B", "Choice C" };
    			// The below line of code does not produce the output that I am seeking.
    			String[] strChoices = { strMixedTogetherString };
    			ChoiceGroup cgChoices = new ChoiceGroup("Select one or more", List.MULTIPLE, strChoices, null);
    			screen.append(cgChoices);

    Any help that could be provided would be greatly appreciated.
    For retrieving the records from record store and adding them into array of String you can do following task-

    String [] sArray=new String[testDb.getNumRecords()];
    for(int j=1,i=0;j<=intNumberOfRecords;j++,i++)
    {
    byte [] data=testDb.getRecord(j);
    sArray[i]=new String(data);
    }

    and finally add that String array while creating object of choice group
    Regards,
    Pradip

  4. #4
    Regular Contributor
    Join Date
    Sep 2011
    Posts
    73

    Re: Need help populating a choice group from a record store.

    Thank you for the information, Pradip.

Similar Threads

  1. How to populate a choice group from a record store?
    By John_123 in forum Mobile Java General
    Replies: 2
    Last Post: 2011-10-11, 23:48
  2. CHOICE GROUP POPUP
    By deepakkinni in forum Mobile Java General
    Replies: 6
    Last Post: 2010-08-10, 12:20
  3. Choice Group
    By mrjayaram in forum Mobile Java General
    Replies: 5
    Last Post: 2010-07-12, 05:47
  4. store and read MULTIPLE choice group strings..plz help
    By ruchitjoshi in forum Mobile Java Tools & SDKs
    Replies: 0
    Last Post: 2005-11-14, 20:32
  5. Choice Group Oddness
    By mrmop in forum Mobile Java General
    Replies: 1
    Last Post: 2003-12-19, 01:32

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •