的EditText列表中不工作应该的样子 [英] EditText in a list aren't working the way they should

查看:83
本文介绍了的EditText列表中不工作应该的样子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的EditText 的领域的问题的 ListActivity

在code符合所有的权利,但功能很奇怪,在输入第一个字段和隐藏的文字出现在另一个EditField中后,这种键盘。

帮我看看我的逻辑问题

 包com.example.helloandroid;

进口android.app.ListActivity;
进口android.content.Context;
进口android.os.Bundle;
进口android.view.LayoutInflater;
进口android.view.View;
进口android.view.ViewGroup;
进口android.widget.BaseAdapter;
进口android.widget.EditText;
进口android.widget.TextView;

公共类AddComp扩展ListActivity {


静态最终诠释DATE_DIALOG_ID = 0;

        私有类EfficientAdapter扩展了BaseAdapter {
            私人LayoutInflater mInflater;
            私有String [] attitude_names;
            私有String [] attitude_values​​;

            公共EfficientAdapter(上下文的背景下){
                mInflater = LayoutInflater.from(上下文);
                attitude_names = context.getResources()getStringArray(R.array.COMP_ATTITUDE_NAME)。
                attitude_values​​ =新的String [attitude_names.length]
            }

            公共对象的getItem(INT位置){
                返回的位置;
            }

            众长getItemId(INT位置){
                返回的位置;
            }

            公共查看getView(INT位置,查看convertView,ViewGroup中父){
                ViewHolder持有人;

                如果(convertView == NULL){
                    convertView = mInflater.inflate(R.layout.addcomp_attitude_row,NULL);

                    持有人=新ViewHolder();
                    holder.Attitude_Name =(TextView中)convertView.findViewById(R.id.addcomp_att_name);
                    holder.Attitude_Value =(EditText上)convertView.findViewById(R.id.addcomp_att_value);

                    convertView.setTag(保持器);
                } 其他 {
                    支架=(ViewHolder)convertView.getTag();
                }

                holder.Attitude_Name.setText(attitude_names [位置]);
                holder.Attitude_Value.setHint(attitude_names [位置]);
                。attitude_values​​ [位置] = holder.Attitude_Value.getText()的toString();



                返回convertView;
            }

            类ViewHolder {
                TextView的Attitude_Name;
                的EditText Attitude_Value;
            }

            @覆盖
            公众诠释getCount将(){
                返回attitude_names.length;
            }
        }


    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);

        setListAdapter(新EfficientAdapter(本));

        的setContentView(R.layout.addcomp);
    }
}
 

解决方案

问题通过添加条目清单中,并使用了 TextWatcher (这是必要的,因为视图解决一个列表行internly多次调用这意味着,对于500强之列条目PROGRAMM使用row.view级的只有当场打死intances是铁道部高效) therfore它需要使用保存更改的数据的额外datastructur为exsample阵列。

文本守望

 私有类EfficientAdapter扩展了BaseAdapter {
            私人LayoutInflater mInflater;
            私有String [] attitude_names;
            公众的String [] attitude_values​​;
            私人字符串名称;

            公共EfficientAdapter(上下文的背景下){
                mInflater = LayoutInflater.from(上下文);
                attitude_names = context.getResources()getStringArray(R.array.COMP_ATTITUDE_NAME)。
                attitude_values​​ =新的String [attitude_names.length]
            }

            公共对象的getItem(INT位置){
                返回的位置;
            }

            众长getItemId(INT位置){
                返回的位置;
            }

            公共查看getView(INT位置,查看convertView,ViewGroup中父){
                最后ViewHolder持有人;

                如果(convertView == NULL){
                    convertView = mInflater.inflate(R.layout.addcomp_attitude_row,NULL);

                    持有人=新ViewHolder();
                    holder.Attitude_Name =(TextView中)convertView.findViewById(R.id.addcomp_att_name);
                    holder.Attitude_Value =(EditText上)convertView.findViewById(R.id.addcomp_att_value);
                    holder.Attitude_Value.addTextChangedListener(新TextWatcher()
                        {
                            公共无效afterTextChanged(编辑EDT)
                            {
                                attitude_values​​ [holder.ref] = edt.toString();
                            }

                            公共无效beforeTextChanged(CharSequence的arg0中,诠释ARG1,诠释ARG2,诠释ARG3){}

                            公共无效onTextChanged(CharSequence的arg0中,诠释ARG1,诠释ARG2,诠释ARG3){
                                // attitude_values​​ [参考] = At​​titude_Value.getText()的toString();
                            }
                        });

                    convertView.setTag(保持器);
                } 其他 {
                    支架=(ViewHolder)convertView.getTag();
                }


                holder.ref =位置;
                holder.Attitude_Name.setText(attitude_names [位置]);
                holder.Attitude_Value.setHint(attitude_names [位置]);
                holder.Attitude_Value.setText(attitude_values​​ [位置]);




                返回convertView;
            }

            类ViewHolder {
                TextView的Attitude_Name;
                的EditText Attitude_Value;
                诠释裁判;



            }

            @覆盖
            公众诠释getCount将(){
                返回attitude_names.length;
            }
        }
 

I have a problem with EditText fields in a ListActivity.

The code complies all right, but the functionality is strange, typing in the first field and hiding the keyboard after this the text appears in another editfield.

Help me with my logical issue

package com.example.helloandroid;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.TextView;

public class AddComp extends ListActivity {


static final int DATE_DIALOG_ID = 0;

        private class EfficientAdapter extends BaseAdapter {
            private LayoutInflater mInflater;
            private String[] attitude_names;
            private String[] attitude_values;

            public EfficientAdapter(Context context) {
                mInflater = LayoutInflater.from(context);
                attitude_names = context.getResources().getStringArray(R.array.COMP_ATTITUDE_NAME);
                attitude_values = new String[attitude_names.length];
            }

            public Object getItem(int position) {
                return position;
            }

            public long getItemId(int position) {
                return position;
            }

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

                if (convertView == null) {
                    convertView = mInflater.inflate(R.layout.addcomp_attitude_row, null);

                    holder = new ViewHolder();
                    holder.Attitude_Name = (TextView) convertView.findViewById(R.id.addcomp_att_name);
                    holder.Attitude_Value = (EditText) convertView.findViewById(R.id.addcomp_att_value);

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

                holder.Attitude_Name.setText(attitude_names[position]);
                holder.Attitude_Value.setHint(attitude_names[position]);
                attitude_values[position] = holder.Attitude_Value.getText().toString();



                return convertView;
            }

            class ViewHolder {
                TextView Attitude_Name;
                EditText Attitude_Value; 
            }

            @Override
            public int getCount() {
                return attitude_names.length;
            }
        }


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setListAdapter(new EfficientAdapter(this));

        setContentView(R.layout.addcomp);
    }
}

解决方案

Problem solved by adding Entry in manifest and the use of a TextWatcher (this is needed because the view of one list row is internly called several times that means that for 500 list entries the programm uses only afew intances of the row.view-class to be mor efficient) therfore it is need to use a text watcher that saves the changed data in a extra datastructur for exsample an array..

        private class EfficientAdapter extends BaseAdapter {
            private LayoutInflater mInflater;
            private String[] attitude_names;
            public String[] attitude_values;
            private String name;

            public EfficientAdapter(Context context) {
                mInflater = LayoutInflater.from(context);
                attitude_names = context.getResources().getStringArray(R.array.COMP_ATTITUDE_NAME);
                attitude_values = new String[attitude_names.length];
            }

            public Object getItem(int position) {
                return position;
            }

            public long getItemId(int position) {
                return position;
            }

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

                if (convertView == null) {
                    convertView = mInflater.inflate(R.layout.addcomp_attitude_row, null);

                    holder = new ViewHolder();
                    holder.Attitude_Name = (TextView) convertView.findViewById(R.id.addcomp_att_name);
                    holder.Attitude_Value = (EditText) convertView.findViewById(R.id.addcomp_att_value);
                    holder.Attitude_Value.addTextChangedListener(new TextWatcher()
                        {
                            public void afterTextChanged(Editable edt) 
                            {
                                attitude_values[holder.ref] = edt.toString();
                            }

                            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}

                            public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                                //attitude_values[ref] = Attitude_Value.getText().toString();
                            }
                        });

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


                holder.ref=position;
                holder.Attitude_Name.setText(attitude_names[position]);
                holder.Attitude_Value.setHint(attitude_names[position]);
                holder.Attitude_Value.setText(attitude_values[position]);




                return convertView;
            }

            class ViewHolder {
                TextView Attitude_Name;
                EditText Attitude_Value; 
                int ref;



            }

            @Override
            public int getCount() {
                return attitude_names.length;
            }
        }

这篇关于的EditText列表中不工作应该的样子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆