i have a structure like this in my ListView
TextView EditText
TextView EditText
TextView EditText
Btton
when i click on ok button. how to retrieve value from each EditText and print Sum of it on dialog box...any idea....?
i have a structure like this in my ListView
TextView EditText
TextView EditText
TextView EditText
Btton
when i click on ok button. how to retrieve value from each EditText and print Sum of it on dialog box...any idea....?
Assuming your row layout is something like
LinearLayout - TextView - Edittext
You can use something like
for(int i =0;i<getListView.getChildCount();i++){
LinearLayout layout = getListView.getChildAt(i);
String text = layout.getChildAt(1).getText();
}
I would do it this way
Inside my ListAdapter, while creating rows, save a reference to list view in an ArrayList
On click of the button, get the array list from the adapter and iterate through all edittexts
Check out TextWatcher. Add it using:
myEditText1.addTextChangedListener(new GenericTextWatcher(myEditText1));
myEditText2.addTextChangedListener(new GenericTextWatcher(myEditText2));
myEditText3.addTextChangedListener(new GenericTextWatcher(myEditText3));
...
private class GenericTextWatcher implements TextWatcher{
private View view;
private GenericTextWatcher(View view) {
this.view = view;
}
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}
public void afterTextChanged(Editable editable) {
String text = editable.toString();
switch(view.getId()){
case R.id.editText1_id:
// do something
break;
case R.id.editText2_id:
// do something
break;
case R.id.editText3_id:
// do something
break;
}
}
}