Search code examples
javaandroidview

A resources-efficient way to compare views to layouts in Android


I need to check if a certain View has been initialized with a certain layout. What I've done now to solve it is:

if( mView == inflater.inflate( R.layout.main_item, null ) )

Is there a more efficient way to implement this kind of comparison ?


Solution

  • if( mView == inflater.inflate( R.layout.main_item, null ) )
    

    is gonna be always false. Either because mView is or is not null. That's because inflater.inflate returns a new instance of main_item.xml every time it is invoked. You could check the view with getId(), if you assigned one to the root in main_item.xml