Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7551321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:27:48+00:00 2026-05-30T10:27:48+00:00

I have a Listview with custom cursor adapter. I’m trying to prevent input in

  • 0

I have a Listview with custom cursor adapter. I’m trying to prevent input in edittext field from being recycled. I’ve been working with a Hashmap. It works when you first scroll down (to not use data from 0 etc in the newly shown view). But when you scroll back up it recycles inputs again. I’m hoping someone here can spot my issue bc I’ve looked at other post with issue on recycled inputs with edittext and I can’t see what I’m doing wrong compared to what worked for other.

public class editview extends ListActivity {
    private dbadapter mydbhelper;
    public static int editCount;
    public static ListView listView;
    public ItemAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mydbhelper = new dbadapter(this);
            mydbhelper.open();


        View footer = getLayoutInflater().inflate(R.layout.footer_layout, null);
        ListView listView = getListView();
        listView.addFooterView(footer);
        showResults();
        }

    //Populate view
    private void showResults (){
        Cursor cursor = mydbhelper.getUserWord();
        startManagingCursor(cursor);
        String[] from = new String[] {dbadapter.KEY_USERWORD};
         int[] to = new int[] {R.id.textType};
         adapter = new ItemAdapter(this, R.layout.edit_row, cursor,
                        from, to);
            adapter.notifyDataSetChanged();
            this.setListAdapter(adapter);
            editCount = adapter.getCount();

    }


            //footer button
            public void onClick(View footer){
                    final MediaPlayer editClickSound = MediaPlayer.create(this, R.raw.button50);
                    editClickSound.start();
                    startActivity(new Intent("wanted.pro.madlibs.OUTPUT"));

                }
...         
//custom cursor adapter
class ItemAdapter extends SimpleCursorAdapter {

    private LayoutInflater mInflater;
    private Cursor cursor;
    static Map<Integer, String> inputValues = new LinkedHashMap<Integer, String>();
    static String oldText;


    public ItemAdapter(Context context, int layout, Cursor cursor, String[] from,
            int[] to) {
        super(context, layout, cursor, from, to);
        this.cursor = cursor;
        mInflater = LayoutInflater.from(context);

    }


    static class ViewHolder {
        protected TextView text;
        protected EditText edittext;

        }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {


        ViewHolder holder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.edit_row, null);


             holder = new ViewHolder();
            holder.text = (TextView) convertView.findViewById(R.id.textType);
            holder.edittext = (EditText) convertView.findViewById(R.id.editText);


            convertView.setTag(holder);

        } else {
            holder = (ViewHolder) convertView.getTag();

        }
        cursor.moveToPosition(position);
        int label_index = cursor.getColumnIndex("userword"); 
        String label = cursor.getString(label_index);

        holder.text.setText(label);
        oldText =  inputValues.get(position);
        holder.edittext.setText(oldText == null ? "" : oldText);


        holder.edittext.addTextChangedListener(new TextWatcher(){
            public void afterTextChanged(Editable editable) {
                inputValues.put(position, editable.toString());
                //Log.e(String.valueOf(position), "position in Hashmap");
                //Log.e(inputValues.get(position), "data in Hashmap");
            }

            public void beforeTextChanged(CharSequence s, int start,
                    int count, int after) {
                // TODO Auto-generated method stub

            }

            public void onTextChanged(CharSequence s, int start,
                    int before, int count) {
                // TODO Auto-generated method stub

            }

        });

        return convertView;

    }
}

I tried this below code but it ended up having my recycled view called position 0.

static class ViewHolder implements TextWatcher {
    protected TextView text;
    protected EditText edittext;
    protected int position;

    public void afterTextChanged(Editable editable) {
        Log.e(String.valueOf(position), "Position in array");
        Log.e(editable.toString(), "data in array");
        inputValues.put(position, editable.toString());

    }
    public void beforeTextChanged(CharSequence s, int start, int count,
            int after) {
        // TODO Auto-generated method stub

    }
    public void onTextChanged(CharSequence s, int start, int before,
            int count) {
        // TODO Auto-generated method stub

    }

    }

@Override
public View getView(final int position, View convertView, ViewGroup parent) {


    ViewHolder holder;
    if (convertView == null) {
        convertView = mInflater.inflate(R.layout.edit_row, null);


         holder = new ViewHolder();
        holder.text = (TextView) convertView.findViewById(R.id.textType);
        holder.edittext = (EditText) convertView.findViewById(R.id.editText);
        holder.position = position;
        holder.edittext.addTextChangedListener(holder);

        convertView.setTag(holder);

    } else {....
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T10:27:50+00:00Added an answer on May 30, 2026 at 10:27 am

    You probably want to remove old TextWatcher instances before adding new ones. Looks like you have scope for multiple TextWatchers watching the same EditText for multiple positions in the list, which could end up looking like view recycling gone wrong.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ListView with custom adapter which is populated from local sqlite database.
I have a custom cursor adapter I'm using to fill a ListView. The inflater
I'm trying to delete items from a ListView using a custom adapter which extends
I have a ListView with a custom Adapter that extends ArrayAdapter. It's a ArrayAdapter
I have a a listview with each row having a text field and edittext
I have a ListView with a custom CursorAdapter feed from a MatrixCursor . Each
Summary: Trying to dynamically add heading rows to a ListView via a custom adapter
I'm trying to display information from a Cursor in a ListView , each row
I have ListView with custom Adapter which supplies View to ListView in this way:
I have a custom cursor adapter and I'd like to put an image into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.