动态生成的textview如何在kotlin中做findViewByTag它显示无法解析的引用

我创建了一个TextView动态使用Kotlin,如果我想通过使用标签设置值为textview它显示findViewWithTag作为未解决的参考错误。

 val textview = findViewWithTag("201") as TextView 

如果我使用findViewById它显示id应该是@IdRes正常的整数不被接受。

 val textview = findViewById(201) 

创建动态文本视图: https ://nelsoncvjr.wordpress.com/2013/05/12/addremove-layout-dynamically-on-android/

  public static void add(final Activity activity, final String value, final String hint, final boolean required) { final LinearLayout linearLayoutForm = activity.findViewById(R.id.linearLayoutForm); final RelativeLayout newView = (RelativeLayout) activity.getLayoutInflater().inflate(R.layout.row_form, null); newView.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); newView.setTag(hint); final TextView tvRequired = newView.findViewById(R.id.tvRequired); tvRequired.setTag(required); if (required) tvRequired.setVisibility(View.VISIBLE); else tvRequired.setVisibility(View.GONE); final TextInputEditText textInputEditText = newView.findViewById(R.id.etValueEt); //textInputEditText.setId(getCode(hint, activity)); textInputEditText.setText(value); textInputEditText.setHint(hint); linearLayoutForm.addView(newView); }