简体   繁体   中英

Android Studio XML Layout file exist but I can't find it

I wanted to create a Fragment in Android Studio , so I did the following steps:

  1. Right click on package
  2. New -> Android (Other) -> Fragment (List)
  3. Checked both include fragment factory methods? and switch to grid view on large screens

The description said "Creates a new fragment containing a list that can optionally change to grid when on large screens."

Here's the funny part: As I was reading the code to understand how this switching is done, I could not find any code that switched XML files or anything. The only odd thing that I found is that the XML used for the Adapter was called R.layout.fragment_item , but there was no XML called like that in my layout folder.

There were 2 XML called R.layout.fragment_item_list and R.layout.fragment_item_grid . So I though "hey, maybe internally the framework auto decide if going for _grid or _list and that's why it doesn't mark R.layout.fragment_item it as non-existent"

When I was done reading the code, I deleted both R.layout.fragment_item_list and R.layout.fragment_item_grid from my layout folder and guess what? R.layout.fragment_item is NOT marked as non-existent, and there is no such file inside my Layout folder.

I already went Build > Clean and Build > Rebuild Project and it still marks it as existent. Am I missing something here? sounds like there is some basic stuff I haven't taken into account.

Just found what was going on. Inside values/refs.xml there was <item name="fragment_item" type="layout">@layout/fragment_item_grid</item> which should be the cause of it.

I had the same issue, I didn't understand your solution as I couldn't see refs.xml in the values folder.

For anybody out there, this is what worked for me: In Android Studio go to File -> Invalidate Caches / Restart...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM