我从数据库中获取项目名称并附加到自定义列表视图中的editext。现在我在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;
}
}
答案 0 :(得分:0)
您可以在类范围中使用declare String变量,并且每次使用system.out.println进行打印。所以就在它下面,它将新字符串附加到字符串变量。
String str;//in the class scope
str = str.concat(Caption.getText().toString());//just below your
system.out.print(str);
试试吧
答案 1 :(得分:0)
创建一个静态变量
static String str="";
str = str + Caption.getText().toString();
最后,您将获得单个字符串中的所有值