An open API service indexing awesome lists of open source software.

https://github.com/queeniecplusplus/android_review_24

GridView, Pass Param between two diff Destination within NavigationUI
https://github.com/queeniecplusplus/android_review_24

android e-commerce fragment gridview kotlin listadapter simpleadapter

Last synced: 2 months ago
JSON representation

GridView, Pass Param between two diff Destination within NavigationUI

Awesome Lists containing this project

README

          

# Android_Review_24
GridView, Pass Param between two diff Destination within NavigationUI

![](https://raw.githubusercontent.com/QueenieCplusplus/Android_Review_24/main/output1.png)

![](https://raw.githubusercontent.com/QueenieCplusplus/Android_Review_24/main/output2.png)

![](https://raw.githubusercontent.com/QueenieCplusplus/Android_Review_24/main/output3.png)

# safe-args:

top level build gradle =>

dependencies {

def nav_version = "2.3.3"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"

...

}

app level build gradle =>

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs.kotlin'

}

dependencies {

// Navigation
implementation "android.arch.navigation:navigation-fragment-ktx:$version_navigation"
implementation "android.arch.navigation:navigation-ui-ktx:$version_navigation"

}


# pass pararm betweem 2 diff destination using Bundle =>


sending frag:


this.component!!.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
Toast.makeText(this.activity, "selected item:" + label[position], Toast.LENGTH_SHORT).show()


// pass param between 2 destinations
val j = label[position].toString()
val bundle = bundleOf("j" to j)
findNavController().navigate(R.id.action_mainFragment_to_detailFragment, bundle)



//findNavController().navigate(action_mainFragment_to_detailFragment)
}


receiving frag:

// pass param between 2 destinations
var st = arguments?.getString("j")
this.tv2!!.text = st



# Navigation

set Navigaton Host on Activity_Main.xml =>




add 2 diff fragments, then .... add them to nav_graph

res/navigation/nav_graph.xml =>







# GridView

add GridView component in one of the fragment to do overview UI.




within its items show in Gridview. (as same as RecycleView)




onViewCreated phase of the overview frag =>


val view: View = inflater.inflate(R.layout.main_fragment, container, false)
//gv = view.findViewById(R.id.gv)

val items = ArrayList>()
for (i in img.indices) {
val item = HashMap()
item["image"] = img[i]
item["text"] = label[i]
items.add(item)
}

val kadapter = SimpleAdapter(this.activity,
items, R.layout.grid_view_item, arrayOf("image", "text"),
intArrayOf(R.id.img, txt))

gv = view.findViewById(R.id.gv)

this.gv!!.adapter = kadapter
this.gv!!.numColumns = 2
this.gv!!.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
Toast.makeText(this.activity, "selected item:" + label[position], Toast.LENGTH_SHORT).show()
val j = label[position].toString()
//val i = img[position].toInt()
// pass param between 2 destinations
val bundle = bundleOf("j" to j)
//val bundle = bundleOf("i" to i)
findNavController().navigate(R.id.action_mainFragment_to_detailFragment, bundle)
//findNavController().navigate(action_mainFragment_to_detailFragment)

}
return view

Ref:

https://www.itread01.com/content/1544675943.html (debug)

https://proandroiddev.com/migrating-the-deprecated-kotlin-android-extensions-compiler-plugin-to-viewbinding-d234c691dec7 (kotlin-android-extensions is deprecated)

https://stackoverflow.com/questions/65185166/disable-kotlin-android-extensions-deprecation-warning kotlin-android-extensions is deprecated)

https://developer.android.com/guide/navigation/navigation-pass-data (pass data)

https://www.jianshu.com/p/ffa19d26f65f (fragment)

https://stackoverflow.com/questions/44214136/what-does-r-drawable-image-return (type cast)

https://givemepass.blogspot.com/2011/11/gridview.html (SimpleAdapter & GridView)

http://hk.uwenku.com/question/p-cnphanaq-vu.html (GridView)