i need to adding any number editext and remove button in android listview using a add row button(consider a row having edittext and a button (name remove row)) ,we having the provision to add any number of rows also able to delete any number of columns, when we adding new rows the old editext with already entered values need to be there and can read the whole edittext value too.when press remove button in row remove the row.Newly entered row must come in the top. looking for urs valued feed back, thanking you.
-
I Guess what u want is to add something on your row from the edittext and the clear the field when u click on the remove button. If i m wrong.Rectify it – Terril Thomas Oct 11 '12 at 06:07
2 Answers
Your question is a bit unclear to me. Also I am not near my dev machine, so you can go with these guidelines. (You may have to change things)
To add an EditText
EditText et = new EditText(...);
yourView.addView(et);
As you want the new EditText to be at the top, you need to set the alignment programmatically:
RelativeLayout.Layoutparams params = (RelativeLayout.LayoutParams)et.getLayoutParams();
params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
// OR do this:
params.addRule(RelativeLayout.ABOVE, R.id.edit_text_will_be_above_this);
et.setLayoutParams(params);
// And then add the view
yourView.addView(et);
Finally, to remove it:
et.setVisibility(View.GONE);

- 6,630
- 5
- 34
- 49
What I understand of the question:
- You need to add a new row on a button click, new row should be the first one to be displayed. The new row will have some default values.
- There is a button in each row called
remove
, onClick you need to remove that row.
If I am correct, here are the answers (presuming you know how to assign eventhandler to buttons):
I would suggest to use an ArrayList to get the adapter and then populate it. On row add, insert at begining the data to be inserted in a new row using add and then get the adapter and populate listview. Make the listview an instance variable.
You may want to check out a previous sof question on assigning eventhandlers to views inside a row or this sof question on same topic for assiging the event. For deleting, use remove method of arraylist with index that of the selected row. Remove the element, form new adapter and populate the listview.