0

我通过 url 从服务器数据库中获取所有菜单名,我使用基本适配器将所有菜单名附加到 editext 自定义列表视图中。现在我将 Edittext 更改的值放入列表数组。现在我想存储 edittext 所有值,无论他是否更改菜单名称。例如:x,yz ... 来自数据库的菜单名称附加到 editext 现在我将菜单名称 y 更改为 b和 z 到 c 在 editext.now 我想要 [x,bc..] 值在arraylist 但现在我得到 b,c

          this is my code
            public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;


    if (convertView == null) {
        holder = new ViewHolder();
        convertView = inflater.inflate(R.layout.editmainmenulist, null);
        holder.caption = (EditText) convertView
                .findViewById(R.id.editmaimenu);
        holder.caption1=(ImageView) convertView.findViewById(R.id.menuimage);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    //Fill EditText with the value you have in data source
    holder.caption.setText(itemnames[position]);//here only i append database menunames
    holder.caption.setId(position);
    holder.caption1.setImageBitmap(bmps[position]);

    //we need to update adapter once we finish with editing
    holder.caption.setOnFocusChangeListener(new OnFocusChangeListener() {
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus){
                final int position = v.getId();
                final EditText Caption = (EditText) v;
                itemnames[position] = Caption.getText().toString();

                arr.add(Caption.getText().toString());//here only i think problem..please see any body can tell what i have mistake has been done


            }
        }    
    });     

    return convertView;
}
      }

           class ViewHolder {
EditText caption;
ImageView caption1;
      }

    class ListItem {
String caption;
     }

我想要所有的edittext值,无论editext值是否改变。有目的的更新。我可以得到所有以前的菜单名。我想将旧菜单名更新为新菜单名

4

1 回答 1

1

添加TextChangedListener到您EditTextgetView()

代码:

holder.caption.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)
    {
    // TODO Auto-generated method stub
    String data =  holder.caption.getText().toString().trim();
    }
});

现在在需要时从 edittext 获取数据,onTextChanged、beforeTextChanged 或 afterTextChanged..

于 2012-04-09T05:11:46.663 回答