嗨我做了一个程序,当我在我的editText中输入数字时,它会自动显示包含等于我输入的数字的edittexts的tablerow,我使用for循环来做到这一点,但我希望在每个循环中它都会改变编辑文本的背景颜色我将如何做到这一点,在此先感谢...
这是我的代码...
final EditText et = (EditText)findViewById(R.id.questions);
Button button1 = (Button)findViewById(R.id.btn);
button1.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String c = et.getText().toString();
Integer count = Integer.parseInt(c);
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);
txt.setText("Question ");
txt2.setText("Excellent ");
txt3.setText("Best ");
txt4.setText("Better ");
txt5.setText("Good ");
txt6.setText("Poor ");
table.addView(tableRow);
int j=0;
for(j = 1; j<=count; j++){
tableRow = new TableRow (getApplicationContext());
TextView name = new TextView (getApplicationContext());
EditText et2 = new EditText (getApplicationContext());
EditText et3 = new EditText (getApplicationContext());
EditText et4 = new EditText (getApplicationContext());
EditText et5 = new EditText (getApplicationContext());
EditText et6 = new EditText (getApplicationContext());
et2.setBackgroundColor(Color.WHITE);
et3.setBackgroundColor(Color.WHITE);
et4.setBackgroundColor(Color.WHITE);
et5.setBackgroundColor(Color.WHITE);
et6.setBackgroundColor(Color.WHITE);
tableRow.addView(name);
tableRow.addView(et2);
tableRow.addView(et3);
tableRow.addView(et4);
tableRow.addView(et5);
tableRow.addView(et6);
table.addView(tableRow);
}
setContentView(table);
}
});