Harsh
Harsh

Reputation: 487

How to inflate a layout?

I've tabs as activities. In one of the tabs I have a search dialog. When I inflate the search result my tabs disappear. How can I inflate the result while preserving the tabs?

Here's how I inflate the result:

LinearLayout layout = (LinearLayout) findViewById(R.id.quick_search);

if(data==null) {

    LinearLayout empty = (LinearLayout) mInflater.inflate(R.layout.empty, null);

    layout.addView(empty);

}
else {

    LinearLayout workRequest = (LinearLayout) mInflater.inflate(R.layout.quick_search, null);

    layout.addView(workRequest);
}

Actually I want to display the searched result in place of LinearLayout 'quick_search' and make sure that the view above 'quick_search' is not lost. My current method inflates the result to occupy the whole screen. How can I avoid that?

Upvotes: 0

Views: 749

Answers (3)

Nirali
Nirali

Reputation: 13825

See the below link

https://stackoverflow.com/a/2336047/1441666

RelativeLayout item = (RelativeLayout)findViewById(R.id.item);
View child = getLayoutInflater().inflate(R.layout.child);
item.addView(child);

Upvotes: 1

user1417127
user1417127

Reputation: 1645

You need a ActivityGroup within the Tab where you want to change the Activity. If you just go on and create a new Activity and display it, your Tab Layout is no longer visible. See this: http://united-coders.com/nico-heid/use-android-activitygroup-within-tabhost-to-show-different-activity

Upvotes: 0

Jason L
Jason L

Reputation: 1832

If quick_search or empty have layout attributes of layout_width and/or layout_height set to match_parent, then they will occupy the whole screen when you inflate them. Either set them to wrap_content or some fixed value to avoid this.

Upvotes: 0

Related Questions