main.xml
<ListView android:id="@+id/listView1" android:layout_width="match_parent" android:layout_height="wrap_content" android:animationCache="false" android:scrollingCache="false" android:smoothScrollbar="true" > </ListView>
Create an ArrayList, add data to the arraylist.
lv=(ListView)findViewById(R.id.listView1); lv.setItemsCanFocus(true); for(int i=0;i<30 data-blogger-escaped-br="" data-blogger-escaped-i=""> list.add(i); }
1) create an adapter for the list and set it as a tag for edittext.
2) Usually when you scroll a position, the position changes. So you should get the edittext tag and set it to edittext id. Because of this, you can avoid changing the position of a position.
holder.caption = (EditText) convertView .findViewById(R.id.editText12); holder.caption.setTag(position); holder.caption.setText(list.get(position).toString()); convertView.setTag(holder); }else { holder = (ViewHolder) convertView.getTag(); } int tag_position=(Integer) holder.caption.getTag(); holder.caption.setId(tag_position);
Finally, add a text observer to the edittext and save the changes to the correct position in the list.
holder.caption.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { final int position2 = holder.caption.getId(); final EditText Caption = (EditText) holder.caption; if(Caption.getText().toString().length()>0){ list.set(position2,Integer.parseInt(Caption.getText().toString())); }else{ Toast.makeText(getApplicationContext(), "Please enter some value", Toast.LENGTH_SHORT).show(); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) {
Link to this link .. http://velmuruganandroidcoding.blogspot.in/2014/08/edittext-in-listview-android-example.html
source share