Reputation: 97
I am developing an app which has long forms so its kind of difficult to manually do findViewById for each screen. I have following structure in the screen where I am stuck.
Relative layout
->TableLayout
-->TableRow
--->And then each table row has 3 edittext in its own columns.
I am doing this
TableLayout table = (TableLayout)findViewById(R.id.screen8_table1);
int rowCount = table.getChildCount();
TableRow rows = (TableRow)table.getChildAt(0);
int viewCount = rows.getChildCount();
EditText thisView = new EditText(getApplicationContext());
View theView = rows.getChildAt(1);
int Id = theView.getId();
thisView.findViewById(Id);
text = thisView.getText().toString();
Log.i("View value",text);
When I try to get the ID is shows -1. Please help.
After the answer from Pavneet Singh I made this one change in the code
FloatLabeledEditText et_one = (FloatLabeledEditText)rows.getChildAt(1);
text = et_one.getEditText().getText().toString();
and now its working properly. Save me a tons of lines of code here!
Upvotes: 1
Views: 56
Reputation: 37404
You are creating a new EditText
which is not a child of TableRow
.
EditText thisView = new EditText(getApplicationContext());
View theView = rows.getChildAt(1);
int Id = theView.getId();
You can directly fetch it as
EditText eText_one = (EditText)rows.getChildAt(1);
// no need to use any id to fetch edittext reference
text = eText_one.getText().toString();
Update : you are using customize editext so use
com.wrapp.floatlabelededittext.FloatLabeledEditText et_one =
(com.wrapp.floatlabelededittext.FloatLabeledEditText)rows.getChildAt(1);
Although this can be achieved with TextInputLayout provided by design library
Upvotes: 3