How do I access the created EditTexts in the following code? I can easily access the text from the EditText boxes created in the xml, but how do I capture what is entered into the created EditText boxes found in my for loop?:
public class Game extends Activity implements OnClickListener { private static final String TAG = "Matrix"; static int entry1; static int entry2; static int entry3; static int entry4; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.matrix); View doneButton = findViewById(R.id.done_button); doneButton.setOnClickListener(this); for(int i = 0; i < MatrixMultiply.h1; i++){ TableLayout table = (TableLayout)findViewById(R.id.myTableLayout); TableRow row = new TableRow(this); EditText column = new EditText(this); for(int j = 0; j < MatrixMultiply.w1; j++){ table = (TableLayout)findViewById(R.id.myTableLayout); column = new EditText(this); column.setId(i); row.addView(column); } table.addView(row); } } public void onClick(View v) { switch (v.getId()) { case R.id.done_button: Intent k = new Intent(this, GameTwo.class); final EditText e1 = (EditText) findViewById(R.id.entry1); entry1 = Integer.parseInt(e1.getText().toString()); final EditText e2 = (EditText) findViewById(R.id.entry2); entry2 = Integer.parseInt(e2.getText().toString()); final EditText e3 = (EditText) findViewById(R.id.entry3); entry3 = Integer.parseInt(e3.getText().toString()); final EditText e4 = (EditText) findViewById(R.id.entry4); entry4 = Integer.parseInt(e4.getText().toString()); startActivity(k); //finish(); break; } }
e1.getText().toString(), so you are accessing the text inside the EditText.