0

hi i made a program that have EditText... i used for loop to set the number of my EditText, i cant get the value of my EditText(excellent), how can i do that? please help me..my output goes this way...

enter image description here


i want that 3,2,5,1,4 will display in my EditText,,



here are my codes...

  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!                                //  
           //******************************************************************************//
Dio Baccay
  • 83
  • 8

3 Answers3

1

The problem is that this

output.append(a+",");

Prints a representation of the object a, not the strings that a contains. Try somthing like this:

for(String s : a){
    output.append(s);
}
Simon
  • 6,293
  • 2
  • 28
  • 34
0

Your split function should be followed by a FOR loop. Split gives you a array. So you need to iterate the array and append inside the lopp. Example

  String str = "one-two-three";

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

      // Append your output with val here 

  }

Cheers

0

There are multiple things going wrong here.

  1. you split on "," but that is not what you want. you want the excellent.getText().toString(); of the EditTexts
  2. You append the text it is just after creation. It will be empty string at that time.

What you want to do

  1. Make an ArrayList of EditText
  2. Put all excellent EditTexts in it.
  3. In the onClick go through this list and append all the getText().toString() of these EditTexts

I won't give you an exact implementation. You should be able to figure that out on your own.

Ivo
  • 18,659
  • 2
  • 23
  • 35
  • sir i made it this way final StringBuilder output = new StringBuilder(); for(int z=1;z<=count;z++){ ArrayList firstlist = new ArrayList(); firstlist.add(excellent); } it only retrive the last input – Dio Baccay Nov 13 '13 at 12:55