0

我从数据库中获取项目名称并附加到自定义列表视图中的编辑文本。现在我正在更改edittext中的值我可以打印我正在打印的内容我想要存储一个变量

我的代码:

             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]);
        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();
                    System.out.println(Caption.getText().toString());//here only i am printing all values i want store all values into one varible
                }
            }
        });

        return convertView;
    }
}
4

2 回答 2

0

您可以在类范围内使用声明字符串变量,并且每次使用 system.out.println 进行打印。所以就在它下面将新字符串附加到字符串变量。

String str;//in the class scope

str = str.concat(Caption.getText().toString());//just below your 
system.out.print(str);

试试看

于 2012-04-06T08:13:11.953 回答
0

create one static variable

static String str="";
str = str + Caption.getText().toString();

at last you will get all values in single string

于 2012-04-06T08:22:51.263 回答