简体   繁体   中英

Android: Many Edittexts in ListView

this is my getView method:

    public View getView(final int position, View convertView, final ViewGroup parent) {
        ViewHolder holder;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.propviewlistrow, null);
            holder.title = (TextView) convertView.findViewById(R.id.propviewlistrow_t1);
            holder.content = (EditText) convertView.findViewById(R.id.propviewlistrow_e1);
            convertView.setTag(holder);
        }
        else{
            holder = (ViewHolder)convertView.getTag();
        }
        holder.title.setText(names.get(position));
        holder.content.setText(values.get(position));       
        holder.content.addTextChangedListener(new TextWatcher(){

            public void afterTextChanged(Editable s) {      
                values.set(position, s.toString());
            }

            public void beforeTextChanged(CharSequence s, int start,
                    int count, int after) {
            }

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

        });
        return convertView;
    }
}

But this does not work. The edittexts do not display the proper text, the displayed text switches while scrolling. The next issue is, I have set android:windowSoftInputMode="adjustPan" in the manifest. If you click the into the last edittext, the listview won't scroll up enough so that you can see what you are typing.

Sorry for not answering your question directly, but if i were you i'd redesign that list. It's gonna be major PITA for the user to use edit fields in the list. What i'd do - either use long-press action and bring dialog or dialog activity to edit, or use quick actions pattern

http://android-developers.blogspot.com/2010/05/twitter-for-android-closer-look-at.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM