BVtp
BVtp

Reputation: 2480

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 ?

Upvotes: 1

Views: 235

Answers (2)

Barrrettt
Barrrettt

Reputation: 819

For my future self, by example:

int itemId = view.getId();
int resID =  getLayoutInflater().inflate(R.layout.my_view, null ).getId();
if (itemId == resID )return true;

if view is kind of resouce then return true

Upvotes: 0

Blackbelt
Blackbelt

Reputation: 157457

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

Upvotes: 1

Related Questions