0

我正在创建自定义列表视图。将数据传递给 edittext 。当时它显示一个错误

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


        if (convertView == null) {
            holder = new ViewHolder();

            convertView = inflater.inflate(R.layout.editfoodmenulistview, null);
            holder.caption = (EditText) convertView
                    .findViewById(R.id.foodmenu);

            holder.caption1=(ImageView) convertView.findViewById(R.id.foodimage);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        //Fill EditText with the value you have in data source

        holder.caption.setText(itemnames[position]);
        holder.caption.setId(position);
        holder.caption.setFocusableInTouchMode(true);

        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;
                    Caption.setFocusable(true);

                    holder.caption.setFocusable(true);
                    arr.remove(holder.caption.getId());
                    arr.add(holder.caption.getId(),holder.caption.getText().toString());


            }
                }

        });  



        return convertView;
    }
     }

      view holder(this is class)

 class ViewHolder {
 EditText caption;
ImageView caption1;
}

 class ListItem {
String caption;
}

上面的viewholder类我用了一些其他的类来获取edittext。现在我想将相同的edittext重用到另一个类..它显示一个错误..请告诉我如何解决这个错误

4

1 回答 1

0

改变这个:

convertView = inflater.inflate(R.layout.editfoodmenulistview, null);

对此:

convertView = inflater.inflate(R.layout.editfoodmenulistview, parent, false);
于 2012-04-23T07:12:24.240 回答