How to get data from dynamically created EditText using LayoutInflater in android?

bgorkhe picture bgorkhe · Jan 22, 2014 · Viewed 7.3k times · Source

This is Relative Layout view which is created dynamically like this :

Layout

... So my question is how to get the values from those dynamic elements and perform some calculation to show result on textview which is also dynamically created. Thanks in advance guys!!

    public void goButtonClicked(View view) {
    maalContainer.removeAllViews();
    int numberofPlayersTolayout = (Integer) Integer.parseInt((String) numberOfPlayers.getSelectedItem());

    LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);

    for (int i = 0; i < numberofPlayersTolayout; i++) {
        View dynamicEntryView = inflater.inflate(R.layout.player_entry_item, null);
        maalContainer.addView(dynamicEntryView, params);
    }

}

}

Answer

Digvesh Patel picture Digvesh Patel · Jan 22, 2014
for (int i = 0; i < maalContainer.getChildCount(); i++) {
    View view = maalContainer.getChildAt(i);

    EditText ed_item = (EditText) view
            .findViewById(R.id.edittext1);
    EditText ed_value = (EditText) view
            .findViewById(R.id.edittext2);
    EditText ed_value1 = (EditText) view
            .findViewById(R.id.edittext3);

    ed_item.getText().toString().trim();
    ed_value.getText().toString().trim();
    ed_value1.getText().toString().trim();
}