0

嗨我做了一个程序EditText......我用for循环来设置我的数量EditText,我无法获得我的价值EditText(优秀),我该怎么做?请帮帮我..我的输出是这样的...

在此处输入图像描述


我希望 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+",");

打印 object 的表示a,而不是a包含的字符串。尝试这样的事情:

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

你的 split 函数后面应该有一个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 回答
0

这里有很多问题。

  1. 你分裂了“,”但这不是你想要的。你想要excellent.getText().toString();EditText
  2. 您在创建之后附加文本。那时它将是空字符串。

你想做什么

  1. ArrayList一个EditText
  2. 把所有优秀EditText的s都放进去。
  3. onClick浏览此列表并附加所有getText().toString()这些EditTexts

我不会给你一个确切的实现。你应该能够自己解决这个问题。

于 2013-11-13T12:03:18.410 回答