I was working on my app and i need to make a list of little groups of views like this :
(i couldn't post my image 'cause StackOverflow thing i'm not famous enought)
The fragment is shown , and correctly applied but the view group that i'm trying to display doesn't.
I can't find how to make my fragment apprear and make the buttons work (But that's not the point now , so I'll ask the question later)
class EditFragment : Fragment() {
lateinit var option : Spinner
lateinit var result : TextView
private lateinit var viewOfLayout: View
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
viewOfLayout = inflater.inflate(R.layout.edit_fragment, container, false)
val mainLayout = viewOfLayout.findViewById(R.id.scrollView1) as ScrollView
//create a view to inflate the layout_item (the xml with the textView created before)
val view = layoutInflater.inflate(R.layout.sensor_item, mainLayout, false)
val options = arrayOf("A","V")
option = view.spinner as Spinner
result = view.textView7 as TextView
option.adapter = ArrayAdapter<String>(activity,android.R.layout.simple_list_item_1,options)
return viewOfLayout
}
}
Here is the full code : https://pastebin.com/fYyXkupM
(I precise that my fragment is displaying properly)
-> I think my error is comming from there :
val view = layoutInflater.inflate(R.layout.sensor_item, mainLayout, false)
if i replace "mainLayout" by "container" it does works but it's not the fragment's child.
Thank you.
ok , even if that's a little specific , i found my answer :
val view = layoutInflater.inflate(R.layout.sensor_item, container, false)
val insertPoint = viewOfLayout.findViewById(R.id.box_Parent) as LinearLayout
insertPoint.addView(view2, 0)