I created row
# android
h
I created row
n
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
sure
but is this slack not about also solving problems ?
so it could be an example for others also in case they need
n
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
oh ok sure
no problem
I mean my code should be fine s I did read and watched examples
n
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
yes exactly
that is a provided library
n
Copy code
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
but I need to set it to scanner layout
as it has the camera and scanner
is not it correct ?
n
Yes, and you want to overlay stuff on top of it?
or just get the result from the scanning operation?
h
it opens that scanning layout, scans and get the result
n
if you just need the result, you can do it as part of another activity, and then just return the result via intents
h
which I do
I fill a list
n
I think from memory you need to do the scanning operation (or at least it is easier) from a separate activity
h
Copy code
booksMutable.add(Book(rawResult.text.toLong()))
that is a mutableList
n
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
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
Copy code
06-25 17:20:00.076 8652-8652/com.okan.pc.mylbrary.app I/System.out: books size 1
n
yea, it’s because you aren’t inflating your own layout
you are just inflating the scanner layout
so the recycler view is never actually created unfortunately
h
but am I not doing it here
Copy code
my_recycler_view?.layoutManager = LinearLayoutManager(this)
        my_recycler_view?.adapter = MainAdapter(booksMutable)
on
Copy code
onHandleResult
n
that bit looks correct
it is
Copy code
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
it is already an activity itself
Copy code
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
Copy code
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
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
it is in main activity
is notit
that is where I show it
n
Copy code
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
I also have that on
Copy code
onCreate
of my main activity
Copy code
setContentView(R.layout.activity_main)
Copy code
<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
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
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
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
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
no worries, best of luck 👍