bukanamay
bukanamay

Reputation: 575

How do I check the type of a widget programmatically in Android?

I want to check the type of a widget programmatically.

View v = tabHost.getTabWidget().getChildAt(i);

How do I check if v is a RelativeLayout or LinearLayout?

Upvotes: 1

Views: 355

Answers (1)

Austyn Mahoney
Austyn Mahoney

Reputation: 11408

View v = tabHost.getTabWidget().getChildAt(i);

if(v instanceof RelativeLayout) {
    // RelativeLayout
} else if (v instanceof LinearLayout){
    // LinearLayout
}

Although you probably should use findViewById() to find the Widget you want.

View v = tabHost.getTabWidget().findViewById(R.id.myLinearLayoutView);

Upvotes: 3

Related Questions