I'm having a strange problem in Android Studio.
I have got my activity_chords_list.xml file with a RecyclerView
inside it that looks like this:
<android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/chords_recycler"
android:layout_below="@+id/layout_top"
android:layout_alignParentStart="true"
android:layout_marginTop="50dp" />
But in my onCreate()
method it isn't recognised:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chords_list);
chordsList = (RecyclerView) findViewById(R.layout.chords_recycler);
and I get the following two errors:
Expected resource of type ID
cannot resolve symbol chords_recycler
Any idea on how to fix it?
Change
android:id="@id/chords_recycler"
for
android:id="@+id/chords_recycler"
From the documentation :
The plus-symbol (+) means that this is a new resource name that must be created and added to our resources (in the R.java file).
And you need to access it using R.id.chords_recycler
:
chordsList = (RecyclerView) findViewById(R.id.chords_recycler);
我认为您应该使用此:
chordsList = (RecyclerView) findViewById(R.id.chords_recycler);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.