0

こんにちは、プログラムを作成しましたEditText... for ループを使用して my の数を設定しましたEditText。my EditText(excellent) の値を取得できません。私を助けてください..私の出力はこのようになります...

ここに画像の説明を入力


に 3,2,5,1,4 が表示されるようにしたいEditText,,



ここに私のコードがあります...

  final TableLayout table = new TableLayout(getApplicationContext());
            table.setVerticalScrollBarEnabled(true);
            table.setPadding(10, 10, 10, 10);



            TableRow tableRow = new TableRow (getApplicationContext());             


            TextView txt = new TextView (getApplicationContext());
            TextView txt2 = new TextView (getApplicationContext());
            TextView txt3 = new TextView (getApplicationContext());
            TextView txt4 = new TextView (getApplicationContext());
            TextView txt5 = new TextView (getApplicationContext());
            TextView txt6 = new TextView (getApplicationContext());

            tableRow.addView(txt);
            tableRow.addView(txt2);
            tableRow.addView(txt3);
            tableRow.addView(txt4);
            tableRow.addView(txt5);
            tableRow.addView(txt6);



            tableRow.setBackgroundColor(Color.GRAY);

            txt.setText("Question  ");
            txt2.setText("Excellent   ");
            txt3.setText("Best     ");
            txt4.setText("Better   ");
            txt5.setText("Good     ");
            txt6.setText("Poor     ");

            txt.setTextColor(Color.BLACK);
            txt2.setTextColor(Color.BLACK);
            txt3.setTextColor(Color.BLACK);
            txt4.setTextColor(Color.BLACK);
            txt5.setTextColor(Color.BLACK);
            txt6.setTextColor(Color.BLACK);


            table.addView(tableRow);

            TableRow tableRow2 = null;
            EditText excellent = null;
            EditText best = null;
            EditText better = null;
            EditText good = null;
            EditText poor = null;

            TextView name = null;




            int j=0;
            for(j = 1; j<=count; j++){

                Random rnd = new Random(); 
                int color = Color.argb(255, rnd.nextInt(256), rnd.nextInt(256), rnd.nextInt(256)); 

                 tableRow2  = new TableRow (getApplicationContext());
                 excellent = new EditText (getApplicationContext());
                 best = new EditText (getApplicationContext());
                 better = new EditText (getApplicationContext());
                 good = new EditText (getApplicationContext());
                 poor = new EditText (getApplicationContext());

                 name = new TextView (getApplicationContext());
                 //i want to retrive the value of this --->//excellent.setBackgroundColor(color);
                best.setBackgroundColor(color);
                better.setBackgroundColor(color);
                good.setBackgroundColor(color);
                poor.setBackgroundColor(color);


                name.setText("Q#"+Integer.toString(j));

                tableRow2.addView(name);
                tableRow2.addView(excellent);
                tableRow2.addView(best);
                tableRow2.addView(better);
                tableRow2.addView(good);
                tableRow2.addView(poor);
                table.addView(tableRow2);




            }
            final StringBuilder output = new StringBuilder();
            final String[]  a = excellent.getText().toString().split(",");
            output.append(a+",");



            TableRow tableRow1 = new TableRow (getApplicationContext());

            Button get = new Button(getApplicationContext());
            tableRow1.addView(get);
            get.setText("Get!");
            get.setTextSize(8);




             //******************************************************************************// 
            //                              GET!                                    //  
           //******************************************************************************//

            get.setOnClickListener(new OnClickListener(){




                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub

                    EditText x = new EditText (getApplicationContext());
                    x.setText(output);
                    table.addView(x);


                }

            });

             //******************************************************************************// 
            //                               END OF GET!                                //  
           //******************************************************************************//
4

3 に答える 3

1

問題は、これが

output.append(a+",");

a含まれる文字列ではなく、object の表現を出力しaます。次のようなことを試してください:

for(String s : a){
    output.append(s);
}
于 2013-11-13T11:34:46.207 に答える
0

分割関数の後にはFORループが続く必要があります。Split は配列を提供します。したがって、配列を反復処理して、lopp 内に追加する必要があります。例

  String str = "one-two-three";

  for (String val: str.split("-", 2)){

      // Append your output with val here 

  }

乾杯

于 2013-11-13T11:34:44.240 に答える