For my android application I need to implement a tabView within a LinearLayout. I could able to add textview and button to the LinearLayout like this,
public CreateView(Context context) {
super(context);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
Button button = new Button(context);
button.setText("Submit");
button.setLayoutParams(llp);
TextView tv = new TextView(context);
tv.setText("This is a test");
tv.setLayoutParams(llp);
ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT);
this.addView(tv);
this.addView(button);}
In my Activity class I added these as,
public class MyLinearLayout extends Activity {
LinearLayout ll;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ll = new LinearLayout(this);
ll.addView(new CreateView(this));
setContentView(ll);
}
}
I want to do the same thing for a tabview. But I couldn’t able to find a way to add tabHost to my lineaLayout. any way to do this??
thanx
When defining the TabHost in xml and adding tabs programmatically with tabHost.newTabSpec like it’s shown in tutorial, the following structure is created:
I guess you need to replicate this nesting in code.
The root-LinearLayout in the xml-version has width and height set to fill_parent and orientation to vertical. Maybe that’s also required for it to work.