I have the following function in java and I need to convert it to Kotlin.
@Override
public void afterTextChanged(Editable s) {
if (s != null && !"".equals(s.toString())) {
int position = (Integer) mHolder.numEdit.getTag();
// Saved to the data variable when the data changes
mData.get(position).put("list_item_inputvalue",
s.toString());
}
}
This is the equivalent Kotlin code that I've created:
override fun afterTextChanged(s: Editable?) {
if (s != null && "" != s.toString()) {
val position = mHolder.numEdit!!.tag as Int
// Saved to the data variable when the data changes
mData?.get(position).put("list_item_inputvalue", s.toString())
}
}
The compiler doesn't like the call to .put(). The variable mData in Java is:
private List<Map<String, String>> mData;
and Kotlin:
var mData: List<Map<String, String>>? = null
Why doesn't the compiler like the conversion of put in Kotlin?
UPDATE:
println(mData) = [{list_item_inputvalue=0}, {list_item_inputvalue=1},...]
println(mData?.get(position)) = {list_item_inputvalue=8}
