user2542715
user2542715

Reputation: 185

How can I detect layout type from object?

l have an object that can contain any type of layout. How can I detect layout type ? I have an idea only with try/catch.

Upvotes: 0

Views: 56

Answers (3)

L. G.
L. G.

Reputation: 9761

Example:

final ViewGroup layout = yourObject.getMyLayout();
if (layout instanceof LinearLayout) {
  //do something
}
else if (layout instanceof TableLayout){
  // do something else
}

Upvotes: 1

Cob50nm
Cob50nm

Reputation: 961

Little bit clunky but you could have an if statement like this

if(this.getCurrentFocus().getId() ==  R.layout.myLayout)
 {
   String layoutType = "Linear";
 }

or do whatever you need to with the result

Upvotes: 0

bongo
bongo

Reputation: 763

try instanceof operator

layout instanceof Linearlayout

Upvotes: 0

Related Questions