enter image description here
As you can see in above the above code, a Textview which has id: photo_title is not recognized even though I have created a TextView in content_photo_details.xml with the ID: photo_title.
I’m a beginner who’s creating an Image display app using a tutorial. I want the app to display the photo alongside info when clicked. The app worked smoothly until now, it displayed all the photos one below other but when I try to include the code for displaying the full photo, I run into this problem.
I’ve provided the code for content_photo_details.xml and activity_photo_details.xml
PhotoDetailsActivity.kt:
package com.example.flickrbrowser
import android.os.Bundle
import com.example.flickrbrowser.databinding.ActivityPhotoDetailsBinding
import com.squareup.picasso.Picasso
class PhotoDetailsActivity : BaseActivity() {
private lateinit var binding: ActivityPhotoDetailsBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityPhotoDetailsBinding.inflate(layoutInflater)
setContentView(binding.root)
// setContentView(R.layout.activity_photo_details)
activateToolbar(true)
val photo = intent.getSerializableExtra(PHOTO_TRANSFER) as Photo
binding.photo_title.text = photo.title
}
}
activity_photo_details.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".PhotoDetailsActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_photo_details" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
content_photo_details.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".PhotoDetailsActivity">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_photo_details" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginEnd="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Aaryan Goswami is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.