Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello all,
would you be kind to have a look a look at the piece of my code bellow and help
with string retrieve from stringbuilder. What I want to do is split the stringbuilder, convert it to string and get the 1st and 2nd
element and use them as bundle input for database.
Thanks in advance

C#
@Override
            public void onClick(View v) {
                  StringBuilder checkedcontacts= new StringBuilder();
                System.out.println(".............."+ma.mCheckStates.size());
                for(int i = 0; i < name1.size(); i++)

                    {
                    if(ma.mCheckStates.get(i)==true)
                    {
                                      	
                    	checkedcontacts.append(name1.get(i).toString());
                        checkedcontacts.append(" ");
                        checkedcontacts.append(phno1.get(i).toString());
       
                    }
                    else
                    {
                        System.out.println("Not Checked......"+name1.get(i).toString());
                    }

                    
                }

                Toast.makeText(Display.this, checkedcontacts,
                Toast.LENGTH_SHORT).show();
Posted
Updated 13-May-14 5:47am
v2

1 solution

Probably it should change like this:
C#
for(int i = 0; i < name1.size(); i++)

                    {
                    if(ma.mCheckStates.get(i)==true)
                    {

                        checkedcontacts.append(name1.get(i).toString());
                        checkedcontacts.append(" ");
                        checkedcontacts.append(phno1.get(i).toString());
                        break; // break your loop
                    }
                    else
                    {
                        System.out.println("Not Checked......"+name1.get(i).toString());
                    }


                }

                Toast.makeText(Display.this, checkedcontacts.toString(),
                Toast.LENGTH_SHORT).show(); // you didn't use toString()
 
Share this answer
 
Comments
[no name] 14-May-14 23:32pm    
Dear Xiao Ling,
thanks a lot for your help.
it's solved now.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900