I'm just starting to learn android app development as well as java, and I'm a bit confused how to get this to work. I created user input fields in the UI with the following tablelayout:
public void inputRow( TableLayout tl, String label, int inputSize, int inputID )
{
TableRow inputRow = new TableRow(this);
TextView tv = new TextView(this);
EditText edit = new EditText(this);
// some margin
inputRow.setPadding( 20,10,20,0);
tv.setText(label);
edit.setMaxWidth( inputSize*7) ;
edit.setMinimumWidth(inputSize*7);
edit.setId( inputID );
edit.setGravity(Gravity.RIGHT);
inputRow.addView(tv);
inputRow.addView(edit);
tl.addView(inputRow);
}
I then filled out the inputRows with the following:
inputRow( myTableLayout, "Name", 30, 10000);
inputRow( myTableLayout, "Last Name", 20, 10001);
inputRow( myTableLayout, "Age", 3, 10002);
inputRow( myTableLayout, "Street Address", 20, 10003);
inputRow( myTableLayout, "State", 15, 10004);
Created the button
Button btAccept = new Button(this);
btAccept.setText( "Save");
btAccept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
alertDialog.show();
}
});
And the alert dialogue:
final AlertDialog alertDialog;
alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Save");
alertDialog.setMessage("Saved..");
Rather than just displaying "Saved.." in the alert dialogue, how do I get it to display the actual info the user submitted once they click the button? While I have the id's set for each input row, I'm unsure how to actually retrieve them. Would it make the most sense for me to also place all the input within an aray to then display?
EDIT I've been searching online for possible solutions and thought maybe I need to look at each TableRow from myTableLayout.
TableRow row1 = (TableRow)myTableLayout.getChildAt(0);
TextView tv1 = (TextView) row1.getChildAt(0);
String input = tv1.getText().toString();
I figured that maybe I would be able to access the first row from my table to retrieve the textview output. However it still doesn't work. I really thought I could perhaps access each line with the id I've set with each editText, but nothing I'm trying works.