Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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);
    }

}

}

like image 331
bgorkhe Avatar asked Dec 11 '22 08:12

bgorkhe


1 Answers

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();
}
like image 137
Digvesh Patel Avatar answered May 08 '23 15:05

Digvesh Patel