简体   繁体   中英

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 ?

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

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