Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error 'No resource identifier found' with Android sample project

Tags:

android

I am trying to open the Android sample project - Navigation Drawer in Android Studio, but got error while building it.

These are the steps to reproduce it:

  1. From Android Studio welcome page, select Import an Android code sample
  2. Search for Navigation Drawer, select it and click 'Next'
  3. Specify project location and click 'Finish'

Error:(43) No resource identifier found for attribute 'layoutManager' in package 'com.example.android.navigationdrawer'

Android Studio version is - 1.4 Beta 4

Thanks in advance for any help.

like image 855
Liuting Avatar asked Sep 16 '15 11:09

Liuting


2 Answers

You can certainly still define LayoutManagers and more via xml. Here's an example using the native GridLayoutManager:

<android.support.v7.widget.RecyclerView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/posters_recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:orientation="vertical"
    app:layoutManager="android.support.v7.widget.GridLayoutManager"
    app:reverseLayout="false"
    app:spanCount="3"
    app:stackFromEnd="false" />

If you want to use a custom LayoutManager follow the rules defined here:

R.attr.html#layoutManager

like image 32
worked Avatar answered Oct 18 '22 20:10

worked


The compiler cannot find this attribute in the activity_navigation_drawer.xml:

app:layoutManager="LinearLayoutManager"

To fix this

  1. Remove this attribute from the XML so your Recyclerview looks like this:

    <android.support.v7.widget.RecyclerView
    android:id="@+id/left_drawer"
    android:scrollbars="vertical"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="left|start"
    android:choiceMode="singleChoice"
    android:divider="@null"/>
    
  2. press the Gradle Sync button

  3. In NavigationDrawerActivity, add the following 2 lines of code in your OnCreate();

    LinearLayoutManager mLinearLayoutmanager = new LinearLayoutManager(this);
    mDrawerList.setLayoutManager(mLinearLayoutmanager);
    

So your code now looks like this:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_navigation_drawer);

    mTitle = mDrawerTitle = getTitle();
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (RecyclerView) findViewById(R.id.left_drawer);

    LinearLayoutManager mLinearLayoutmanager = new LinearLayoutManager(this);
    mDrawerList.setLayoutManager(mLinearLayoutmanager);
    ....

Good luck

Edit: The reason why this the original xml code is no longer working, is most likely that the xmlns:app="http://schemas.android.com/apk/res-auto" namespace is no longer supporting the layoutManager attribute.

More info on the namespace can be found here: https://stackoverflow.com/a/26692768/3708094

like image 159
RWIL Avatar answered Oct 18 '22 20:10

RWIL