hereの指示に従って、文字列の配列を文字列に変換しようとしていますが、削除できないnullがいくつかあります。
私が使用しているコード:
まず、textviews に入力し、結果で配列を作成します。
public void doCalculations(){
//write number of teeth for every cog from a 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){
for (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){
for (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){
for (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);
}
}
}
結果をメールで送信する機能
private void mail(){
Intent i = 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 are no...", Toast.LENGTH_LONG).show();
}
}
ここにメール本文を書きます。
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;
文字列の配列を文字列に変換する:
public static String implodeArray(String[] inputArray, String glueString){
String output= "";
if(inputArray.length > 0){
StringBuilder sb = new StringBuilder();
sb.append(inputArray[0]);
for (int i=1; i<inputArray.length;i++){
sb.append(glueString);
sb.append(inputArray[i]);
}
output=sb.toString();
}
return output;
}
携帯電話の画面では、次のように表示されます: 2 列、各チェーンリングに 1 つ、10 行、各コグに 1 つ。
結果をメールで送信すると、次のようになります。
アルテグラ 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
私はかなり迷っています、手を貸してもらえますか?
ありがとう!