0

我在列表视图中使用了edittext。对于使用的editText addTextChangedListner。每当我更改editText中的数据时,我都想在我的hashmap中更新并在listview中更新edittext。但是相同的数据会更新到所有edittext。如何解决这个问题。

我还在下面的文本中添加了代码。

私有类 RSSListAdaptor 扩展 ArrayAdapter{

        private List<RSSItem> objects = null;

        public RSSListAdaptor(Context context, int textviewid, List<RSSItem> objects) {
                super(context, textviewid, objects);

                this.objects = objects;
        }

        @Override
        public int getCount() {
                return ((null != objects) ? objects.size() : 0);
        }

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

        @Override
        public RSSItem getItem(int position) {
                return ((null != objects) ? objects.get(position) : null);
        }

        public View getView(final int position, View convertView, ViewGroup parent) {
                View view = convertView;

                TextView title;
                TextView date;
                EditText description ;
                if(null == view)
                {
                        LayoutInflater vi = (LayoutInflater)RSSFeedActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        view = vi.inflate(R.layout.rssitemview, null);
                        title = (TextView)view.findViewById(R.id.txtTitle);
                        date = (TextView)view.findViewById(R.id.txtDate);
                        description = (EditText)view.findViewById(R.id.txtDescription);
                }
                else
                {
                    LinearLayout linear=(LinearLayout) convertView;
                      title = (TextView) linear.getChildAt(0);
                      date = (TextView) linear.getChildAt(1);
                      description = (EditText) linear.getChildAt(2);


                }
                final RSSItem data = getItem(position);

                System.out.println("getView   "+position+"Data  "+position+"    "+data.toString());

                if(null != data)
                {
                        title.setText(data.title);
                        date.setText("on " + data.date);
                        try
                        {
                            if(descriptionArrayList.get(position)!=null)
                            {
                                description.setText(descriptionArrayList.get(position)+"");
                            }
                        }
                        catch(Exception e)
                        {
                            description.setText("");
                        }
                         description.addTextChangedListener(new TextWatcher() {

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

                            }

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

                            }

                            @Override
                            public void afterTextChanged(Editable s) {
                                Log.v("Position    :"+position, "Value :"+s.toString());
                                //data.description=s.toString();
                                try
                                {
                                    descriptionArrayList.add(position, s.toString());
                                }
                                catch(Exception e)
                                {
                                    descriptionArrayList.add("");
                                }
                            }
                        });

                }

                return view;
        }

}

4

0 回答 0