This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Gu1Fragment : Fragment() { | |
// ... | |
// dynamically add a button to the fragment | |
// beware it is in onViewCreated, should NOT be in onCreateView | |
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | |
super.onViewCreated(view, savedInstanceState) | |
val btn :Button = Button(requireContext()) | |
btn.setText("Manually added by code") | |
// a linear layout in the framgment layout xml | |
val layout: LinearLayout = view.findViewById(R.id.gu_layout) | |
layout.addView(btn) | |
} | |
} |
No comments:
Post a Comment