Set up recycler view for country codes
This commit is contained in:
parent
981107de36
commit
14edd3c38d
36
app/src/main/java/net/helcel/beendroid/ListAdapter.kt
Normal file
36
app/src/main/java/net/helcel/beendroid/ListAdapter.kt
Normal file
@ -0,0 +1,36 @@
|
||||
package net.helcel.beendroid
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckBox
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
|
||||
class ListAdapter(private val dataSet: List<String>) :
|
||||
RecyclerView.Adapter<ListAdapter.ViewHolder>() {
|
||||
|
||||
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
|
||||
val textView: TextView
|
||||
val checkBox: CheckBox
|
||||
|
||||
init {
|
||||
textView = view.findViewById(R.id.textView)
|
||||
checkBox = view.findViewById(R.id.checkBox)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): ViewHolder {
|
||||
val view = LayoutInflater.from(viewGroup.context)
|
||||
.inflate(R.layout.item_list, viewGroup, false)
|
||||
|
||||
return ViewHolder(view)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(viewHolder: ViewHolder, position: Int) {
|
||||
viewHolder.textView.text = dataSet[position]
|
||||
}
|
||||
|
||||
override fun getItemCount() = dataSet.size
|
||||
|
||||
}
|
@ -6,14 +6,19 @@ import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.annotation.Nullable
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.caverock.androidsvg.SVG
|
||||
import com.caverock.androidsvg.SVGImageView
|
||||
import net.helcel.beendroid.R
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private var map : SVGImageView? = null
|
||||
private lateinit var map : SVGImageView
|
||||
private lateinit var list : RecyclerView
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -21,7 +26,6 @@ class MainActivity : AppCompatActivity() {
|
||||
setContentView(R.layout.activity_main)
|
||||
map = findViewById(R.id.map)
|
||||
|
||||
|
||||
val cm = HashMap<Country,SVGWrapper>()
|
||||
Country.values().forEach { c->
|
||||
cm[c] = SVGWrapper(applicationContext,c,Level.ZERO).load()
|
||||
@ -35,7 +39,10 @@ class MainActivity : AppCompatActivity() {
|
||||
canvas.drawRGB(255, 255, 255)
|
||||
|
||||
svg.renderToCanvas(canvas)
|
||||
map?.setImageBitmap(bitmap)
|
||||
map.setImageBitmap(bitmap)
|
||||
|
||||
list = findViewById(R.id.list)
|
||||
list.layoutManager = LinearLayoutManager(applicationContext, RecyclerView.VERTICAL, false)
|
||||
list.adapter = ListAdapter(Country.values().map{ it.code })
|
||||
}
|
||||
}
|
@ -12,4 +12,11 @@
|
||||
android:layout_weight="1"
|
||||
app:css="" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
android:scrollbars="vertical" />
|
||||
|
||||
</LinearLayout>
|
35
app/src/main/res/layout/item_list.xml
Normal file
35
app/src/main/res/layout/item_list.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkBox"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintEnd_toStartOf="@id/textView"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/design_default_color_on_primary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/checkBox"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
||||
|
||||
</FrameLayout>
|
Loading…
x
Reference in New Issue
Block a user