How to implement list view inside fragment android studio Kotlin I am new to programming and I want to make my app a simple listview of names of places by region.
This is the fragment name VisayasMindanao
package com.gumangan.uecficenterslist
import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ArrayAdapter
import android.widget.ListView
class VisayasMindanao : Fragment(){
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val centerlist = resources.getStringArray(R.array.region2)
//Creating Array of Region
var lv = findViewById(R.id.content_main_lview) as ListView
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, centerlist)
lv.adapter = adapter
return LayoutInflater.from(container?.context).inflate(R.layout.visayas_mindanao, container, false)
}
}
This is in my layout name visayas_mindanao
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/visayas_mindanao_lview"/>
</android.support.constraint.ConstraintLayout>
And I'm trying to get values from here
<resources>
<string name="region1">
<item>ARANAAR TI BAGGAK TI DAYA
acarra, Ilocos Norte
</item>
</string>
</resources>