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 7506549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:18:28+00:00 2026-05-29T22:18:28+00:00

I have list item with EditText in it, I don’t know how many items

  • 0

I have list item with EditText in it, I don’t know how many items there will be. I have a problem when I enter some text in EditText, and then scroll down a ListView, after I’ve scroll up again there is no text in my first EditText, or there is some text from other EditText from ListView.

I’ve tried TextWatcher, and saving data to array, but problems is that returned position of view in ListView isn’t always right, so I lost some data from array.

Here is my code:

public class EfficientAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    public String[] Current;
    ArrayList<String> MeterName, PreviousReading, Current_Reading;
    JSONArray getArray_Meter_Reading;

    public EfficientAdapter(Context context, JSONArray getArray_Meter_Reading) {
        mInflater = LayoutInflater.from(context);
        this.getArray_Meter_Reading = getArray_Meter_Reading;
        MeterName = new ArrayList<String>();
        PreviousReading = new ArrayList<String>();
        for (int i = 0; i < getArray_Meter_Reading.length(); i++) {
            try {
                String Meter_Name = getArray_Meter_Reading.getJSONObject(i)
                        .getString("MeterName").toString();
                String previous_Meter_Reading = getArray_Meter_Reading
                        .getJSONObject(i).getString("PrevMeterReading")
                        .toString();
                MeterName.add(Meter_Name);
                PreviousReading.add(previous_Meter_Reading);

                // Meter[i]=MeterName.get(i);
                // Previous[i]=PreviousReading.get(i);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }

    public int getCount() {

        return getArray_Meter_Reading.length();
    }

    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;

        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.meter_reading_list, null);
            holder = new ViewHolder();
            holder.adp_MeterName = (TextView) convertView
                    .findViewById(R.id.txt_Meter_Name);
            holder.adp_Previous = (TextView) convertView
                    .findViewById(R.id.txt_Previous);
            holder.adp_Current = (EditText) convertView
                    .findViewById(R.id.ed_Current);

            holder.adp_Current.addTextChangedListener(new TextWatcher() {

                public void onTextChanged(CharSequence s, int start,
                        int before, int count) {

                }

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

                }

                public void afterTextChanged(Editable s) {

                    Current[holder.ref] = s.toString();

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

        holder.ref = position;
        holder.adp_MeterName.setText(MeterName.get(position));
        holder.adp_Previous.setText(PreviousReading.get(position));
        // holder.adp_Current.setHint(MeterName.get(position));

        // holder.adp_Current.setText(PreviousReading.get(position));

        return convertView;
    }

    class ViewHolder {
        TextView adp_MeterName, adp_Previous;
        EditText adp_Current;
        int ref;

    }

}
  • 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-29T22:18:29+00:00Added an answer on May 29, 2026 at 10:18 pm

    try this:

    public class EfficientAdapter extends BaseAdapter {
    
    private LayoutInflater mInflater;
    public String[] Current;
    ArrayList<String> MeterName, PreviousReading, Current_Reading;
    JSONArray getArray_Meter_Reading;
    public static HashMap<Integer,String> myList=new HashMap<Integer,String>();
    
    public EfficientAdapter(Context context, JSONArray getArray_Meter_Reading) {
        mInflater = LayoutInflater.from(context);
        this.getArray_Meter_Reading = getArray_Meter_Reading;
        MeterName = new ArrayList<String>();
        PreviousReading = new ArrayList<String>();
    
        for (int i = 0; i < getArray_Meter_Reading.length(); i++) {
            try {
                String Meter_Name = getArray_Meter_Reading.getJSONObject(i)
                        .getString("MeterName").toString();
                String previous_Meter_Reading = getArray_Meter_Reading
                        .getJSONObject(i).getString("PrevMeterReading")
                        .toString();
                MeterName.add(Meter_Name);
                PreviousReading.add(previous_Meter_Reading);
    
                // Meter[i]=MeterName.get(i);
                // Previous[i]=PreviousReading.get(i);
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        // initialize myList
        for(int i=0;i<JSON_ARRAY_LENGTH;i++)
        {
           myList.put(i,"");
        }
    }
    
    public int getCount() {
    
        return getArray_Meter_Reading.length();
    }
    
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder holder;
        final int pos=position;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.meter_reading_list, null);
            holder = new ViewHolder();
            holder.adp_MeterName = (TextView) convertView
                    .findViewById(R.id.txt_Meter_Name);
            holder.adp_Previous = (TextView) convertView
                    .findViewById(R.id.txt_Previous);
            holder.adp_Current = (EditText) convertView
                    .findViewById(R.id.ed_Current);
    
    
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
         holder.adp_Current.addTextChangedListener(new TextWatcher() {
    
                public void onTextChanged(CharSequence s, int start,
                        int before, int count) {
    
                }
    
                public void beforeTextChanged(CharSequence s, int start,
                        int count, int after) {
                    // TODO Auto-generated method stub
    
                }
    
                public void afterTextChanged(Editable s) {
    
                    Current[holder.ref] = s.toString();
                    myList.put(pos,s.toString.trim());
                }
            });
        holder.ref = position;
        holder.adp_MeterName.setText(MeterName.get(position));
        holder.adp_Previous.setText(PreviousReading.get(position));
        // holder.adp_Current.setHint(MeterName.get(position));
    
        // holder.adp_Current.setText(PreviousReading.get(position));
    
        holder.adp_Current.setText(myList.get(position));
    
        return convertView;
    }
    
    class ViewHolder {
        TextView adp_MeterName, adp_Previous;
        EditText adp_Current;
        int ref;
    
    }
    
    }
    

    Here I have included a HashMap object which will keep an eye on if EditText contains value or not.And when you scroll the listview,it will be rendered again by calling its getView method along with the text associated with each edittext.

    In this code,when you firstly load listview,all your edittext will be with no text.once you enter some text,it will be noted in myList.So when you again render the list,your text would be prevented.

    One more thing,you should implement textwatcher outside if(convertView==null)..else.. block.That’s a better practice!

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

Sidebar

Related Questions

I have list item with EditText in it, I dont know how many items
I have a list of items. When I create the list each item has
I have some code that inserts a list item into a list... I then
I have a list, and each item is linked, is there a way I
I have a long scrolling list of EditText items created by a SimpleCursorAdapter and
I have a list containing 98 items. But each item contains 0, 1, 2,
I have a list item with buttons in it like so: <mx:List contentBackgroundAlpha=0 baseColor=0x333333
I have a list of 2-item tuples and I'd like to convert them to
I have a list of two-item lists and need to search for things in
Hopefully this is simple: I have a relatively long list where each list item

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.