parent
a2d3e39490
commit
55e7feceed
@ -1,16 +1,43 @@
|
|||||||
package iut.android.pierrepierre
|
package iut.android.pierrepierre
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.PersistableBundle
|
import android.widget.AdapterView.OnItemClickListener
|
||||||
import android.widget.GridView
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
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?) {
|
||||||
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
|
super.onCreate(savedInstanceState)
|
||||||
super.onCreate(savedInstanceState, persistentState)
|
binding = MoleGridBinding.inflate(layoutInflater)
|
||||||
setContentView(R.layout.mole_grid)
|
setContentView(binding.getRoot())
|
||||||
findViewById<GridView>(R.id.MoleGrid).adapter = MyGridAdapter(context = this, Moles)
|
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
|
package iut.android.pierrepierre
|
||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.database.DataSetObserver
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.ArrayAdapter
|
import android.widget.BaseAdapter
|
||||||
import android.widget.ListAdapter
|
import android.widget.ImageView
|
||||||
import androidx.recyclerview.widget.RecyclerView.Adapter
|
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 {
|
override fun getCount(): Int {
|
||||||
return Moles.size
|
return MoleName.size
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItem(position: Int): Any {
|
override fun getItem(position: Int): Any? {
|
||||||
return Moles[position]
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
override fun getItemId(position: Int): Long {
|
||||||
TODO("Not yet implemented")
|
return 0
|
||||||
}
|
|
||||||
|
|
||||||
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")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getViewTypeCount(): Int {
|
override fun getView(position: Int, convertView: View, parent: ViewGroup): View {
|
||||||
TODO("Not yet implemented")
|
var convertView = convertView
|
||||||
}
|
if (inflater == null) inflater =
|
||||||
|
context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||||
override fun isEmpty(): Boolean {
|
if (convertView == null) {
|
||||||
return Moles.isEmpty()
|
convertView = inflater!!.inflate(R.layout.mole_grid, null)
|
||||||
}
|
|
||||||
|
|
||||||
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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:orientation="vertical"
|
||||||
android:layout_height="match_parent">
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:padding="20dp"
|
||||||
|
android:gravity="center">
|
||||||
|
|
||||||
<LinearLayout
|
<ImageView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="150dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="150dp"
|
||||||
android:orientation="vertical">
|
android:scaleType="centerCrop"
|
||||||
<ImageView
|
android:id="@+id/grid_image"/>
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:src="@drawable/ic_launcher_background"/>
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:text="@string/app_name"/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
<TextView
|
||||||
|
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"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Reference in new issue