在我的Android應用程序中,我有與EditTexts
的列表視圖。在更改EditText
值後,我將ArrayList
的新值存儲在afterTextChanged
中。但是在編輯只有一個字段後出現錯誤,ArrayList
獲得了幾個編輯字符串相同的項目。我如何才能讓ArrayList
只爲每個字段編輯一次字符串?文本更改自定義適配器中的EditText的監聽器
class MyListViewAdapter extends ArrayAdapter<KeyValueList>
{
private int layoutResource;
MyListViewAdapter(Context context, int layoutResource, List<KeyValueList> keyValueList)
{
super(context, layoutResource, keyValueList);
this.layoutResource = layoutResource;
}
@Override
public View getView(final int position, final View convertView, @NonNull ViewGroup parent)
{
View view = convertView;
if (view == null)
{
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
view = layoutInflater.inflate(layoutResource, null);
}
final KeyValueList keyValuelist = getItem(position);
if (keyValuelist != null)
{
TextView key = (TextView) view.findViewById(R.id.key);
EditText value = (EditText) view.findViewById(R.id.value);
ImageView image = (ImageView) view.findViewById(R.id.img);
value.addTextChangedListener(new TextWatcher()
{
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
}
@Override
public void afterTextChanged(Editable s)
{
HashMap<String, String> edit = new HashMap<>();
edit.put("string", s.toString());
openEntry.edit_list.add(edit);
}
});
....
}
您需要使用的藥水,在添加新的價值你那個藥水上的「名單」。 – Shailesh