片段不在kotlin中,但在java中的作品(相同的代码)
即时通讯试图在一个FrameLayout内运行一个片段:
来自activity.kt的代码:
... frag.arguments = bundle ft.replace(R.id.framelayout_record, frag, "feedback") // ft.addToBackStack(null) ft.commitNow() ...
这工作:
View root; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { root = inflater.inflate(R.layout.fragment_employee_feedback, container, false); return root; } @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { new AlertDialog.Builder(getActivity()).setMessage("Testtt").show(); }
警报显示正确
但是使用这个:
class TestFragment : Fragment() { internal lateinit var root: View override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { root = inflater!!.inflate(R.layout.fragment_employee_feedback, container, false) return root } override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { AlertDialog.Builder(activity).setMessage("Test Kotlin").show() } }
没有反应,只是显示布局,但没有警报,我不能访问布局元素
- 试图在Android上使用DBFlow和Kotlin的未解决的参考KClass
- 用Kotlin 1.1.2-4编译时的循环依赖关系,而不是1.1.2-3
- 与Android的Kotlin:基类和Kotlin Android扩展
- 用fillafter(true)|查看 kotlin | Android
- Kotlin中的Room Persistence lib实现
- 如何在Kotlin中使用AndroidAnnotation @SharedPref
- Kotlin功能返回值正在保存在firebase中
- 如何避免Kotlin中的lateinit字段的部分覆盖
- 尝试访问继承字段时发生NullPointerException