嗨我制作的程序有EditText
...我用循环来设置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! //
//******************************************************************************//
答案 0 :(得分:1)
问题是这个
output.append(a+",");
打印对象a
的表示形式,而不是a
包含的字符串。尝试这样的事情:
for(String s : a){
output.append(s);
}
答案 1 :(得分:0)
您的分割功能后面应该是 FOR 循环。 Split为您提供了一个数组。 所以你需要迭代数组并附加在lopp中。实施例
String str = "one-two-three";
for (String val: str.split("-", 2)){
// Append your output with val here
}
干杯
答案 2 :(得分:0)
这里有很多问题。
excellent.getText().toString();
的{{1}} 你想做什么
EditText
ArrayList
EditText
放入其中。EditText
中查看此列表并附加onClick
getText().toString()
个
醇>
我不会给你一个确切的实现。你应该能够自己解决这个问题。