我正在创建一个显示记分牌的应用程序,我想在这个应用程序中进行验证。我想验证所有的 Edittexts 我该怎么做。??我想对 EditText 数组执行验证
public class players extends Activity {
LinearLayout player_layout;
Bundle b;
List<EditText> allEds = new ArrayList<EditText>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.players);
b = getIntent().getExtras();
String resStr = b.getString("name");
player_layout = (LinearLayout) findViewById(R.id.player_layout);
EditText[] ed1 = new EditText[Integer.parseInt(resStr)+1];
Button add_player = new Button(players.this);
add_player.setText("Add Players");
for(int i=1;i<=Integer.parseInt(resStr);i++) {
ed1[i] = new EditText(players.this);
allEds.add(ed1[i]);
player_layout.addView(ed1[i]);
ed1[i].setId(i);
ed1[i].setHint("enter player" +i+ "name");
ed1[i].setHeight(50);
ed1[i].setWidth(300);
}
LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
player_layout.addView(add_player, lp);
add_player.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(players.this,player_name.class);
//Intent intent1 = new Intent(players.this,player_name.class);
String[] strings = new String[allEds.size()];
for (int i=0; i < allEds.size(); i++){
strings[i] = allEds.get(i).getText().toString();
// intent.putExtra("playerName",b.getString("name"));
intent.putExtra("playerName",strings);
}
// intent1.putExtra("play",b.getString("name"));
startActivity(intent);
//startActivity(intent1);
}
});
}
}