In all the code where there is R.layout, when I try to enter the name of the xml file, instead of the usual context file with all the names, it shows something completely unknown to me, like abc__action_menu_layout , although I have not used this.
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.ViewParent
import android.widget.ImageView
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import androidx.recyclerview.widget.RecyclerView.Recycler
package com.raindrop.tattoofoundler
import androidx.appcompat.R
import androidx.appcompat.R.layout.news_feed_activity
import androidx.core.content.res.ResourcesCompat
import android.os.Bundle
class Post(
private val posts: List<Post>,
private val viewHolderPool: RecyclerView.RecycledViewPool
) : RecyclerView.Adapter<Post.ViewHolder>() {
class ViewHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) {
val author: TextView = itemView.findViewById(R.id.author)
val time: TextView = itemView.findViewById(R.id.time)
val genre: TextView = itemView.findViewById(R.id.genre)
val photo: ImageView = itemView.findViewById(R.id.photo)
}
override fun onCreateViewHolder(
parent: ViewGroup,
viewType: Int
): Post.ViewHolder {
val layoutResId = R.layout.news_feed_activity
val view = LayoutInflater.from(parent.context)
.inflate(layoutResId, parent, false)
return ViewHolder(view)
}
override fun onBindViewHolder(
holder: Post.ViewHolder,
position: Int
) {
val post = posts[position]
holder.author.text = post.author
holder.time.text = "3 минуты назад"
holder.genre.text = "Anime/DotWork"
holder.photo.setImageResource(R.drawable.sketch5)
}
override fun getItemCount() = posts.size
}
PS - I'm trying to make a RecyclerView to scroll through posts..
XML code -
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:background="@color/purplebg">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="381dp"
android:layout_height="651dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.555"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="388dp"
android:layout_height="162dp"
app:layout_constraintBottom_toTopOf="@+id/recyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<SearchView
android:layout_width="245dp"
android:layout_height="44dp"
android:background="@drawable/searchview"
tools:layout_editor_absoluteX="16dp"
tools:layout_editor_absoluteY="102dp" />
<ImageView
android:id="@+id/imageView14"
android:layout_width="59dp"
android:layout_height="69dp"
app:srcCompat="@drawable/test"
tools:layout_editor_absoluteX="313dp"
tools:layout_editor_absoluteY="11dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/intermedium"
android:text="Говножуйка"
android:textColor="@color/WhiteText5"
android:textSize="15sp"
tools:layout_editor_absoluteX="69dp"
tools:layout_editor_absoluteY="216dp" />
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/interregular"
android:text="3 минуты назад"
android:textColor="@color/GreyText1"
android:textSize="12sp"
tools:layout_editor_absoluteX="168dp"
tools:layout_editor_absoluteY="221dp" />
<TextView
android:id="@+id/genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/interregular"
android:text="Anime/DotWork"
android:textColor="@color/GreyText1"
android:textSize="12sp"
tools:layout_editor_absoluteX="69dp"
tools:layout_editor_absoluteY="238dp" />
<ImageView
android:id="@+id/photo"
android:layout_width="199dp"
android:layout_height="195dp"
app:srcCompat="@drawable/sketch2"
tools:layout_editor_absoluteX="69dp"
tools:layout_editor_absoluteY="263dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
The file is called news_feed_activity.xml. I tried to remove the dashes - failed, I tried to recreate - failed, I tried to change the file name - failed, I tried to give the full path in the main code - also failed, I've already run out of ideas. Due to the fact that he doesn’t see it, he stupidly doesn’t allow me to insert it into the code to do what I wanted(
I don't know if it will solve your issue, but the
package com.raindrop.tattoofoundler
needs to be at the top. Move it to there and it might solve all other issues.
Whenever you see an error it's best to tackle them from top to bottom. You can see that on line 9 it already shows an error