android - Array of strings to a string: Issue using Implode -


following directions found here, i'm trying convert array of strings string, i'm getting nulls can't remove.

the code i've been using:

first, fill in textviews , make array results.

public void docalculations(){     //write number of teeth every cog cassette     for(int i=0; i<casscogs[0]; i++){         tvcogsarray[i].setbackgroundcolor(color.ltgray);         tvcogsarray[i].settext(string.valueof(casscogs[i+1]) +" " + getstring(r.string.teeth));         }      if (integer.parseint(chainringcount) == 1){         (int counter = 0; counter<casscogs[0]; counter++ ){             float temp = (float.parsefloat(wheelsize) *     (float.parsefloat(chainringone) /casscogs[counter + 1] ))/1000;             tvone[counter].settext(string.format("%.2f", temp));              toemail_1[counter] = string.format("%.2f", temp);         }     }else if (integer.parseint(chainringcount) == 2){         (int counter = 0; counter<casscogs[0]; counter++ ){             float temp = (float.parsefloat(wheelsize) * (float.parsefloat(chainringone)/casscogs[counter + 1] ))/1000;             tvone[counter].settext(string.format("%.2f", temp));              toemail_1[counter] = string.format("%.2f", temp);              float second = (float.parsefloat(wheelsize) *(float.parsefloat(chainringtwo)/casscogs[counter+ 1] ))/1000;             tvtwo[counter].settext(string.format("%.2f", second));              toemail_2[counter] = string.format("%.2f", second);          }     }else if (integer.parseint(chainringcount)==3){         (int counter = 0; counter<casscogs[0]; counter++ ){             float temp = (float.parsefloat(wheelsize) *(float.parsefloat(chainringone)/casscogs[counter + 1] ))/1000;             tvone[counter].settext(string.format("%.2f", temp));              toemail_1[counter] = string.format("%.2f", temp);               float second = (float.parsefloat(wheelsize) *(float.parsefloat(chainringtwo)/casscogs[counter + 1] ))/1000;             tvtwo[counter].settext(string.format("%.2f", second));              toemail_2[counter] = string.format("%.2f", second);               float third = (float.parsefloat(wheelsize)*(float.parsefloat(chainringthree)/casscogs[counter+ 1] ))/1000;             tvthree[counter].settext(string.format("%.2f", third));              toemail_3[counter] = string.format("%.2f", third);              }              }        } 

function email results

      private void mail(){      intent = new intent (intent.action_send);     i.settype("message/rfc822");     i.putextra(intent.extra_email, new string[]{});     i.putextra(intent.extra_subject, getapplicationcontext().getstring(r.string.calculos));     i.putextra(intent.extra_text, composebody());      try{         startactivity(intent.createchooser(i, "send mail..."));     }catch (android.content.activitynotfoundexception ex){      toast.maketext(getapplicationcontext(), "there no...", toast.length_long).show();     }  } 

here write email body:

public string composebody(){     string bodytext="";     string join1="";     string join2="";     string join3="";     if(integer.parseint(chainringcount)==1){         if (toemail_1.length >0) {             join1 = implodearray(toemail_1, gluestring);         }         bodytext= bannertext  + linesep + join1;     }else if (integer.parseint(chainringcount)==2){          if (toemail_1.length >0) {             join1 = implodearray(toemail_1, gluestring);         }         if (toemail_2.length >0){             join2=implodearray(toemail_2, gluestring);         }         bodytext= bannertext  + linesep + join1 + linesep + join2;     }else if(integer.parseint(chainringcount)==3){         if (toemail_1.length >0) {             join1 = implodearray(toemail_1, gluestring);         }         if (toemail_2.length >0){             join2=implodearray(toemail_2, gluestring);         }         if(toemail_3.length>0) {             join3=implodearray(toemail_3,gluestring);         }         bodytext= bannertext  + linesep + join1 + linesep + join2 + linesep +join3;              }            return bodytext; 

converting arrays of strings strings:

 public static string implodearray(string[] inputarray, string gluestring){ string output= ""; if(inputarray.length > 0){     stringbuilder sb = new stringbuilder();     sb.append(inputarray[0]);      (int i=1; i<inputarray.length;i++){         sb.append(gluestring);         sb.append(inputarray[i]);     }     output=sb.tostring(); } return output;  } 

on phone screen can see following: 2 columns, 1 each chainring 10 rows, 1 each cog.

results docalculations

when send email results, get:

ultegra 11-28 * 36/46 2,64 * 3,08 * 3,52 * 3,89 * 4,35 * 4,93 * 5,28 * 5,69 * 6,16 * 6,73 * null
3,38 * 3,94 * 4,50 * 4,98 * 5,56 * 6,30 * 6,75 * 7,27 * 7,88 * 8,59 * null

i'm quite lost, can give me hand?

thanks!

your implodearray function seems ok, chances you're putting nulls somewhere in code above. 2 quick tests.-

  • try debugging/logging values you're adding arrays, in

    toemail_1[counter] = string.format("%.2f", temp);

  • just make sure implodearray working, try calling mock array

    implodearray(new string[]{"foo1","foo2","foo3","foo4","foo5","foo6"}, "*")


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -