Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# InClassFragmentActivity
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@

package edu.temple.inclassactivity

import android.media.Image
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.res.TypedArrayUtils
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView

Expand Down Expand Up @@ -40,11 +42,18 @@ class ImageDisplayFragment : Fragment() {
// The recycler view is the root element of the Fragment's layout
// as such the view argument passed to onViewCreated() is the RecyclerView
with (view as RecyclerView) {
adapter = CustomRecyclerAdapter(images)

if(::images.isInitialized) {
adapter = CustomRecyclerAdapter(images)
}

layoutManager = GridLayoutManager(requireContext(), 2)
}
}

fun setImage (temp : IntArray) {
images = temp
(view as RecyclerView).adapter = CustomRecyclerAdapter(images)
}
companion object {
fun newInstance(images: IntArray) =
ImageDisplayFragment().apply {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/edu/temple/inclassactivity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package edu.temple.inclassactivity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.fragment.app.Fragment

class MainActivity : AppCompatActivity() {

//lateinit var someVar : Array<Int>

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Expand All @@ -15,5 +19,14 @@ class MainActivity : AppCompatActivity() {

// Attach an instance of ImageDisplayFragment using factory method

val fragmentTemp : Fragment = ImageDisplayFragment.newInstance(imageArray)

/*
supportFragmentManager
.beginTransaction()
.add(R.id.fragmentContainerView, fragmentTemp)
//.add(R.id.fragmentContainerView, ImageDisplayFragment())
.commit()
*/
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,13 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<androidx.fragment.app.FragmentContainerView
android:name = "edu.temple.inclassactivity.ImageDisplayFragment"
android:id="@+id/fragmentContainerView"
android:layout_width="350dp"
android:layout_height="400dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>