parent
a2d3e39490
commit
55e7feceed
@ -1,16 +1,43 @@
|
||||
package iut.android.pierrepierre
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import android.widget.GridView
|
||||
import android.widget.AdapterView.OnItemClickListener
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
class MoleGridActivity(var Moles : List<Mole>) : AppCompatActivity(){
|
||||
class MoleGridActivity : AppCompatActivity() {
|
||||
///https://developer.android.com/topic/libraries/view-binding#kotlin
|
||||
//var binding: ActivityMainBinding? = null
|
||||
private lateinit var binding : MoleGridBinding
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
|
||||
super.onCreate(savedInstanceState, persistentState)
|
||||
setContentView(R.layout.mole_grid)
|
||||
findViewById<GridView>(R.id.MoleGrid).adapter = MyGridAdapter(context = this, Moles)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
binding = MoleGridBinding.inflate(layoutInflater)
|
||||
setContentView(binding.getRoot())
|
||||
val MoleName = arrayOf(
|
||||
"Mole1", "Mole2", "Mole3", "Mole4",
|
||||
"Mole5", "Mole6", "Mole7", "Mole8", "Mole9", "Mole10"
|
||||
)
|
||||
val flowerImages = intArrayOf(
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule,
|
||||
R.drawable.Limule
|
||||
)
|
||||
val gridAdapter = MyGridAdapter(this@MoleGridActivity, MoleName, flowerImages)
|
||||
binding.gridView.setAdapter(gridAdapter)
|
||||
binding.gridView.setOnItemClickListener(OnItemClickListener { parent, view, position, id ->
|
||||
Toast.makeText(
|
||||
this@MoleGridActivity,
|
||||
"You Clicked on " + MoleName[position],
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
})
|
||||
}
|
||||
}
|
@ -1,78 +1,40 @@
|
||||
package iut.android.pierrepierre
|
||||
|
||||
import android.content.Context
|
||||
import android.database.DataSetObserver
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.ListAdapter
|
||||
import androidx.recyclerview.widget.RecyclerView.Adapter
|
||||
import android.widget.BaseAdapter
|
||||
import android.widget.ImageView
|
||||
import android.widget.TextView
|
||||
|
||||
class MyGridAdapter(context : Context, private var Moles : List<Mole>) : ListAdapter{
|
||||
override fun registerDataSetObserver(observer: DataSetObserver?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun unregisterDataSetObserver(observer: DataSetObserver?) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
// override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Mole {
|
||||
// //return MoleView(LayoutInflater.from(parent.Context).inflate(R.layout.mole_grid))
|
||||
// return Mole(false)
|
||||
// }
|
||||
//
|
||||
// override fun onBindViewHolder(holder: Mole, position: Int) {
|
||||
// TODO("Not yet implemented")
|
||||
// }
|
||||
//
|
||||
// override fun getItemCount(): Int {
|
||||
// TODO("Not yet implemented")
|
||||
// }
|
||||
|
||||
class MyGridAdapter(var context: Context, var MoleName: Array<String>, var image: IntArray) :
|
||||
BaseAdapter() {
|
||||
var inflater: LayoutInflater? = null
|
||||
override fun getCount(): Int {
|
||||
return Moles.size
|
||||
return MoleName.size
|
||||
}
|
||||
|
||||
override fun getItem(position: Int): Any {
|
||||
return Moles[position]
|
||||
override fun getItem(position: Int): Any? {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun hasStableIds(): Boolean {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
TODO("Not yet implemented")
|
||||
return 0
|
||||
}
|
||||
|
||||
override fun getViewTypeCount(): Int {
|
||||
TODO("Not yet implemented")
|
||||
override fun getView(position: Int, convertView: View, parent: ViewGroup): View {
|
||||
var convertView = convertView
|
||||
if (inflater == null) inflater =
|
||||
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
if (convertView == null) {
|
||||
convertView = inflater!!.inflate(R.layout.mole_grid, null)
|
||||
}
|
||||
|
||||
override fun isEmpty(): Boolean {
|
||||
return Moles.isEmpty()
|
||||
}
|
||||
|
||||
override fun areAllItemsEnabled(): Boolean {
|
||||
for (i in Moles){
|
||||
if (i.isDead()){
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
val imageView = convertView.findViewById<ImageView>(R.id.grid_image)
|
||||
val textView = convertView.findViewById<TextView>(R.id.item_name)
|
||||
imageView.setImageResource(image[position])
|
||||
textView.text = MoleName[position]
|
||||
return convertView
|
||||
}
|
||||
|
||||
override fun isEnabled(position: Int): Boolean {
|
||||
return !Moles[position].isDead()
|
||||
}
|
||||
|
||||
|
||||
}
|
After Width: | Height: | Size: 1.7 KiB |
@ -1,20 +1,24 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="20dp"
|
||||
android:gravity="center">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:src="@drawable/ic_launcher_background"/>
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:id="@+id/grid_image"/>
|
||||
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="@string/app_name"/>
|
||||
</LinearLayout>
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/item_name"
|
||||
android:text="Mole"
|
||||
android:textSize="26sp"
|
||||
android:layout_marginTop="6dp"/>
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</LinearLayout>
|
Loading…
Reference in new issue