Set basic onClickListener

This commit is contained in:
Dendy 2022-02-22 21:32:28 +00:00
parent 7f8d8738f8
commit dec94b0011
Signed by: dendy
GPG Key ID: 0168B35FFD7F608F
5 changed files with 26 additions and 4 deletions

View File

@ -3,7 +3,8 @@
<component name="DesignSurface">
<option name="filePathToZoomLevelMap">
<map>
<entry key="app/src/main/res/layout/activity_main.xml" value="0.2" />
<entry key="app/src/main/res/layout/activity_image_viewer.xml" value="0.26132246376811596" />
<entry key="app/src/main/res/layout/activity_main.xml" value="0.33" />
<entry key="app/src/main/res/layout/fragment_image_grid.xml" value="0.2515625" />
<entry key="app/src/main/res/layout/image_grid_item.xml" value="0.35260416666666666" />
</map>

View File

@ -1,7 +1,9 @@
package com.example.testes
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
@ -51,10 +53,17 @@ class ImageGridFragment(val images: List<BooruImage>) : Fragment() {
.load(imageList[position].preview_url)
.placeholder(ContextCompat.getDrawable(context, R.drawable.ic_launcher_foreground))
.into(holder.imageview)
holder.imageview.setOnClickListener(holder)
}
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), View.OnClickListener {
var imageview: ImageView = itemView.findViewById(R.id.image)
override fun onClick(view: View?) {
val intent = Intent(view?.context, ImageViewerActivity::class.java)
startActivity(intent)
}
}
override fun getItemCount(): Int = imageList.size

View File

@ -2,10 +2,16 @@ package com.example.testes
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.LayoutInflater
import com.example.testes.databinding.ActivityImageViewerBinding
import com.example.testes.databinding.ActivityMainBinding
class ImageViewerActivity : AppCompatActivity() {
lateinit var binding: ActivityImageViewerBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_image_viewer)
binding = ActivityImageViewerBinding.inflate(layoutInflater)
setContentView(binding.root)
}
}

View File

@ -6,4 +6,10 @@
android:layout_height="match_parent"
tools:context=".ImageViewerActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/ic_launcher"
/>
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -24,7 +24,7 @@
android:id="@+id/search"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:iconifiedByDefault="false"
app:iconifiedByDefault="false"
android:queryBackground="@android:color/transparent"
/>