https://kotlinlang.org logo
Channels
100daysofcode
100daysofkotlin
100daysofkotlin-2021
advent-of-code
aem
ai
alexa
algeria
algolialibraries
amsterdam
android
android-architecture
android-databinding
android-studio
androidgithubprojects
androidthings
androidx
androidx-xprocessing
anime
anko
announcements
apollo-kotlin
appintro
arabic
argentina
arkenv
arksemdevteam
armenia
arrow
arrow-contributors
arrow-meta
ass
atlanta
atm17
atrium
austin
australia
austria
awesome-kotlin
ballast
bangladesh
barcelona
bayarea
bazel
beepiz-libraries
belgium
benchmarks
berlin
big-data
books
boston
brazil
brikk
budapest
build
build-tools
bulgaria
bydgoszcz
cambodia
canada
carrat
carrat-dev
carrat-feed
chicago
chile
china
chucker
cincinnati-user-group
cli
clikt
cloudfoundry
cn
cobalt
code-coverage
codeforces
codemash-precompiler
codereview
codingame
codingconventions
coimbatore
collaborations
colombia
colorado
communities
competitive-programming
competitivecoding
compiler
compose
compose-android
compose-desktop
compose-hiring
compose-ios
compose-mp
compose-ui-showcase
compose-wear
compose-web
confetti
connect-audit-events
corda
cork
coroutines
couchbase
coursera
croatia
cryptography
cscenter-course-2016
cucumber-bdd
cyprus
czech
dagger
data2viz
databinding
datascience
dckotlin
debugging
decompose
decouple
denmark
deprecated
detekt
detekt-hint
dev-core
dfw
docs-revamped
dokka
domain-driven-design
doodle
dsl
dublin
dutch
eap
eclipse
ecuador
edinburgh
education
effective-kotlin
effectivekotlin
emacs
embedded-kotlin
estatik
event21-community-content
events
exposed
failgood
fb-internal-demo
feed
firebase
flow
fluid-libraries
forkhandles
forum
fosdem
fp-in-kotlin
framework-elide
freenode
french
fritz2
fuchsia
functional
funktionale
gamedev
ge-kotlin
general-advice
georgia
geospatial
german-lang
getting-started
github-workflows-kt
glance
godot-kotlin
google-io
gradle
graphic
graphkool
graphql
graphql-kotlin
graviton-browser
greece
grpc
gsoc
gui
hackathons
hacktoberfest
hamburg
hamkrest
helios
helsinki
hexagon
hibernate
hikari-cp
hire-me
hiring
hiring-french
hongkong
hoplite
http4k
hungary
hyderabad
image-processing
india
indonesia
inkremental
intellij
intellij-plugins
intellij-tricks
internships
introduce-yourself
io
ios
iran
israel
istanbulcoders
italian
jackson-kotlin
jadx
japanese
jasync-sql
java-to-kotlin-refactoring
javadevelopers
javafx
javalin
javascript
jdbi
jhipster-kotlin
jobsworldwide
jpa
jshdq
juul-libraries
jvm-ir-backend-feedback
jxadapter
k2-early-adopters
kaal
kafka
kakao
kalasim
kapt
karachi
karg
karlsruhe
kash_shell
kaskade
kbuild
kdbc
kgen-doc-tools
kgraphql
kinta
klaxon
klock
kloudformation
kmdc
kmm-español
kmongo
knbt
knote
koalaql
koans
kobalt
kobweb
kodein
kodex
kohesive
koin
koin-dev
komapper
kondor-json
kong
kontent
kontributors
korau
korean
korge
korim
korio
korlibs
korte
kotest
kotest-contributors
kotless
kotlick
kotlin-asia
kotlin-beam
kotlin-by-example
kotlin-csv
kotlin-data-storage
kotlin-foundation
kotlin-fuel
kotlin-in-action
kotlin-inject
kotlin-latam
kotlin-logging
kotlin-multiplatform-contest
kotlin-mumbai
kotlin-native
kotlin-pakistan
kotlin-plugin
kotlin-pune
kotlin-roadmap
kotlin-samples
kotlin-sap
kotlin-serbia
kotlin-spark
kotlin-szeged
kotlin-website
kotlinacademy
kotlinbot
kotlinconf
kotlindl
kotlinforbeginners
kotlingforbeginners
kotlinlondon
kotlinmad
kotlinprogrammers
kotlinsu
kotlintest
kotlintest-devs
kotlintlv
kotlinultimatechallenge
kotlinx-datetime
kotlinx-files
kotlinx-html
kotrix
kotson
kovenant
kprompt
kraph
krawler
kroto-plus
ksp
ktcc
ktfmt
ktlint
ktor
ktp
kubed
kug-leads
kug-torino
kvision
kweb
lambdaworld_cadiz
lanark
language-evolution
language-proposals
latvia
leakcanary
leedskotlinusergroup
lets-have-fun
libgdx
libkgd
library-development
lincheck
linkeddata
lithuania
london
losangeles
lottie
love
lychee
macedonia
machinelearningbawas
madrid
malaysia
mathematics
meetkotlin
memes
meta
metro-detroit
mexico
miami
micronaut
minnesota
minutest
mirror
mockk
moko
moldova
monsterpuzzle
montreal
moonbean
morocco
motionlayout
mpapt
mu
multiplatform
mumbai
munich
mvikotlin
mvrx
myndocs-oauth2-server
naming
navigation-architecture-component
nepal
new-mexico
new-zealand
newname
nigeria
nodejs
norway
npm-publish
nyc
oceania
ohio-kotlin-users
oldenburg
oolong
opensource
orbit-mvi
osgi
otpisani
package-search
pakistan
panamá
pattern-matching
pbandk
pdx
peru
philippines
phoenix
pinoy
pocketgitclient
polish
popkorn
portugal
practical-functional-programming
proguard
prozis-android-backup
pyhsikal
python
python-contributors
quasar
random
re
react
reaktive
realm
realworldkotlin
reductor
reduks
redux
redux-kotlin
refactoring-to-kotlin
reflect
refreshversions
reports
result
rethink
revolver
rhein-main
rocksdb
romania
room
rpi-pico
rsocket
russian
russian_feed
russian-kotlinasfirst
rx
rxjava
san-diego
science
scotland
scrcast
scrimage
script
scripting
seattle
serialization
server
sg-user-group
singapore
skia-wasm-interop-temp
skrape-it
slovak
snake
sofl-user-group
southafrica
spacemacs
spain
spanish
speaking
spek
spin
splitties
spotify-mobius
spring
spring-security
squarelibraries
stackoverflow
stacks
stayhungrystayfoolish
stdlib
stlouis
strife-discord-lib
strikt
students
stuttgart
sudan
swagger-gradle-codegen
swarm
sweden
swing
swiss-user-group
switzerland
talking-kotlin
tallinn
tampa
teamcity
tegal
tempe
tensorflow
terminal
test
testing
testtestest
texas
tgbotapi
thailand
tornadofx
touchlab-tools
training
tricity-kotlin-user-group
trójmiasto
truth
tunisia
turkey
turkiye
twitter-feed
uae
udacityindia
uk
ukrainian
uniflow
unkonf
uruguay
utah
uuid
vancouver
vankotlin
vertx
videos
vienna
vietnam
vim
vkug
vuejs
web-mpp
webassembly
webrtc
wimix_sentry
wwdc
zircon
Powered by
Title
h

Hele

06/25/2018, 3:12 PM
I created row
n

neil.armstrong

06/25/2018, 3:12 PM
probably better to use a thread to prevent spam…Could you paste the activity so I can see how you are setting it up?
h

Hele

06/25/2018, 3:12 PM
sure
but is this slack not about also solving problems ?
so it could be an example for others also in case they need
n

neil.armstrong

06/25/2018, 3:13 PM
it is, that’s why I’m helping you 🙂 Just don’t want to send messages to all 15k users at once. It is better to do this kind of thing in a thread if we can
👍 1
h

Hele

06/25/2018, 3:14 PM
oh ok sure
no problem
I mean my code should be fine s I did read and watched examples
n

neil.armstrong

06/25/2018, 3:16 PM
Looks like you are setting the content view to
ZXingScannerView
rather than your activity layout? I haven’t played with scanners in a long time but I think that is a library provided view rather than your own?
h

Hele

06/25/2018, 3:17 PM
yes exactly
that is a provided library
n

neil.armstrong

06/25/2018, 3:17 PM
public override fun onCreate(state: Bundle?) {
        super.onCreate(state)
        mScannerView = ZXingScannerView(this)   // Programmatically initialize the scanner view
        setContentView(mScannerView)                // Set the scanner view as the content view
    }
that means that the call to grab the recycler view won’t work, as it isn’t being shown
Ah man I did do this specific problem years ago with a QR code scanner, I think it was the same library too
h

Hele

06/25/2018, 3:18 PM
but I need to set it to scanner layout
as it has the camera and scanner
is not it correct ?
n

neil.armstrong

06/25/2018, 3:18 PM
Yes, and you want to overlay stuff on top of it?
or just get the result from the scanning operation?
h

Hele

06/25/2018, 3:18 PM
it opens that scanning layout, scans and get the result
n

neil.armstrong

06/25/2018, 3:18 PM
if you just need the result, you can do it as part of another activity, and then just return the result via intents
h

Hele

06/25/2018, 3:18 PM
which I do
I fill a list
n

neil.armstrong

06/25/2018, 3:19 PM
I think from memory you need to do the scanning operation (or at least it is easier) from a separate activity
h

Hele

06/25/2018, 3:19 PM
booksMutable.add(Book(rawResult.text.toLong()))
that is a mutableList
n

neil.armstrong

06/25/2018, 3:20 PM
yea that bit looks fine, just maybe have another look at the ZX examples as it is where your issue is I believe
the kotlin code looks correctly from glancing at it
h

Hele

06/25/2018, 3:20 PM
imo I dont have problem with the scan but maybe setting up the recycler view
as I am able to get the scan result of scan activity
06-25 17:20:00.076 8652-8652/com.okan.pc.mylbrary.app I/System.out: books size 1
n

neil.armstrong

06/25/2018, 3:21 PM
you are just inflating the scanner layout
yea, it’s because you aren’t inflating your own layout
so the recycler view is never actually created unfortunately
h

Hele

06/25/2018, 3:22 PM
but am I not doing it here
my_recycler_view?.layoutManager = LinearLayoutManager(this)
        my_recycler_view?.adapter = MainAdapter(booksMutable)
on
onHandleResult
n

neil.armstrong

06/25/2018, 3:23 PM
that bit looks correct
it is
public override fun onCreate(state: Bundle?) {
        super.onCreate(state)
        mScannerView = ZXingScannerView(this)   // Programmatically initialize the scanner view
        setContentView(mScannerView)                // Set the scanner view as the content view
    }
which is not correct, I think you need to handle the scanning in a separate activity
as your main activity is just showing the ZX layout, not your own xml layout that you have created (with the recycler view)
h

Hele

06/25/2018, 3:24 PM
it is already an activity itself
button_scan.setOnClickListener {
            val intent = Intent(this, ScanActivity::class.java)
            startActivity(intent)

        }
this is how I open scanner activity
maybe I need to open my main activity with an intent
lthough I use a
onBackPressed()
bcoz when I first open the app my list of mutableList shows up as 0 but after I scan and go back to main activity
it does not show size of that list
n

neil.armstrong

06/25/2018, 3:27 PM
Ah I see what you are doing, you need to move your recycler_view logic to the other activity, it cannot be in the
ScanActivity
as it doesn’t show the recycler view
h

Hele

06/25/2018, 3:28 PM
it is in main activity
is notit
that is where I show it
n

neil.armstrong

06/25/2018, 3:28 PM
booksMutable.add(Book(rawResult.text.toLong()))
        val my_recycler_view = findViewById(R.id.my_recycler_view) as RecyclerView?
        my_recycler_view?.layoutManager = LinearLayoutManager(this)
        my_recycler_view?.adapter = MainAdapter(booksMutable)
        println("books size " + booksMutable.size)
this bit I mean, on your
ScanActivity
as it won’t work
h

Hele

06/25/2018, 3:28 PM
I also have that on
onCreate
of my main activity
setContentView(R.layout.activity_main)
<RelativeLayout xmlns:android="<http://schemas.android.com/apk/res/android>"
    xmlns:tools="<http://schemas.android.com/tools>"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/my_recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical" />

    <Button
        android:layout_marginTop="10dp"
        android:id="@+id/button_scan"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="@string/scan_book" />



</RelativeLayout>
n

neil.armstrong

06/25/2018, 3:30 PM
yes, but it doesn’t have the result. The flow will be 1. Start main activity 2. Do some action to start the scan activity via
startActivity
.
var activity = ScanActivity()
creates a different from one Android, so you cannot share data by making a mutable list like you are. 3. On scan successful, receive data in
handleResult
, then send this result data back to the main activity via
startActivity
and an intent. I recommend looking up the Android docs for how to do this
h

Hele

06/25/2018, 3:32 PM
I know how to pass data between activities
I am just new to kotlin
I have already made an app with recycler view in java but in kotlin it just does not work, this app is just for learning purposes 🙂
n

neil.armstrong

06/25/2018, 3:33 PM
from what I can see your approach won’t work in java either though, as it can not share data between the activities
the
my_recycler_view
is not accessible on the
ScanActivity
h

Hele

06/25/2018, 3:35 PM
yeah I get that part
now I am making an intent to share data to main activity
thanks for your help by the way
n

neil.armstrong

06/25/2018, 3:49 PM
no worries, best of luck 👍