Sachin Gurnani
Sachin Gurnani

Reputation: 2444

Android EditText inside ListView?

I have EditText inside ListView and i want to Enter some integer values in all the EditText .I have one Button outside the ListView onClicking that button i want to get the data from all the EditText from ListView and saveinside the database,and also my EditText id is same for all the EditText Can any buddy giving so sample code so i can proceed to nextstep. Thanks in advance.

Upvotes: 4

Views: 2812

Answers (2)

mayur rahatekar
mayur rahatekar

Reputation: 4460

You can use setTag and getTag to find out the position of the Editext Inside the Listview. Inside the getView method use setTag

editText.setTag(position).

And where you have written the Listener just use getTag to take the position.

I have some other requirement that's why I have used the OnTouch listener. But to achieve above requirement that you have mention you have to use Textwatcher. same thing you have to use.

Inside the Listener :

int position = (Integer)view1.getTag();

This position is Unique for each of the row of the ListView.

You have to do setTag Inside the getView() Method of the BaseAdapter class. after the line if(rowview == null){}

Upvotes: 3

Lalit Poptani
Lalit Poptani

Reputation: 67286

You can keep a TextWatcher on the EditText and store the text of EditText in some Data Collection(i.e. ArrayList) and on the Button Click just fetch the data from the Collection and store in the Database.

Upvotes: 1

Related Questions