Android 在自定义适配器内单击“编辑文本”按钮更改文本
如何在列表视图中嵌入的编辑文本中更改文本。我想在单击按钮时更改文本的值Android 在自定义适配器内单击“编辑文本”按钮更改文本,android,Android,如何在列表视图中嵌入的编辑文本中更改文本。我想在单击按钮时更改文本的值 holder.txtQty.setTag(position); holder.plus.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub String
holder.txtQty.setTag(position);
holder.plus.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String val = holder.txtQty.getText().toString();
Float f = new Float(val);
f = f + 1;
holder.txtQty.setText(f.toString().replace(".0", "").trim());
}
});
但在这一点上,只有第一行和最后一行编辑文本更改。我需要相应的编辑文本来更改如果要更改edittext的文本,则可以将其存储在arraylist中。假设单击了第三个元素,则可以从arraylist获取位置,然后设置它。最初使用默认值设置所有值。因此,通过这种方式,您可以设置并最终从arraylist中获取文本。
每次edittext文本将更改时,请获取位置,然后将其保存到arraylist 我将获得您希望更改的文本列表中的位置,编写一个公共方法来替换该位置的内容,然后通知自定义适配器数据集已更改 例如:
public void replaceItemAt(int position, String newText)
{
//Replace the item in the array list
this.textfieldarraylist.set(position, newText);
//Let the custom adapter know it needs to refresh the view
this.notifyDataSetChanged();
}