Reputation: 1076
I've created a layout and I am trying to binding to its IDs.
I have managed to bind to the TextView
's but I was unable to find imageView id for some reason.
public FeedsAdapter(@NonNull Context context, int resource, @NonNull List objects) {
super(context, resource, objects);
this.myFeeds = objects;
this.activity = context;
this.layoutId = resource;
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
LayoutInflater inflater = LayoutInflater.from(this.activity);
convertView = inflater.inflate(this.layoutId, parent, false);
Feed currentFeed = this.myFeeds.get(position);
TextView authorTextView = convertView.findViewById(R.id.author);
TextView dateTextView = convertView.findViewById(R.id.date);
TextView contentTextView = convertView.findViewById(R.id.content);
ImageView imgImageView = (ImageView) convertView.findViewById(R.id.img);
authorTextView.setText(currentFeed.getAuthor());
dateTextView.setText(currentFeed.getDate());
contentTextView.setText(currentFeed.getContent());
return convertView;
}
ImageView imgImageView = (ImageView) convertView.findViewById(R.id.img);
this line return me an error that he doesn't know what is R.id.img
the is the layout XML:
<?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="200dp">
<TextView
android:id="@+id/author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.014"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.033" />
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.045"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.138" />
<TextView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.099"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.845" />
<ImageView
android:id="@+id/img"
android:layout_width="118dp"
android:layout_height="106dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.091"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/a150" />
</androidx.constraintlayout.widget.ConstraintLayout>
btw, I'm looking for an option to put a placeholder for the imageView without put any src
is it possible?
Thanks!
Upvotes: 0
Views: 42
Reputation: 41
This can happen sometimes when the cache in the editor gets out of sync with the resources file. The best way to fix this is by going to File > Invalidate Caches/Restart
Upvotes: 1
Reputation: 84
I have this error on android studio 3.6,but you can compile your code without any failing! close android studio and reopen it, Your error must be fixed, right?!
Upvotes: 1