Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I created a tab host in activity_main.xml that includes two tabs eg: tab1 and tab2
that includes two xml files namely tab1.xml and tab2.xml
Both the tabs has been included in mainactivity.java.

TabHost mytabhost=(TabHost)findViewById(R.id.tabhost);
mytabhost.setup();

TabSpec spec1=mytabhost.newTabSpec("HHU");
spec1.setContent(R.id.settings);
spec1.setIndicator("HHU",getResources().getDrawable(R.drawable.hhu));
TabSpec spec2=mytabhost.newTabSpec("Smart Plug");
spec2.setIndicator("Smart Plug",getResources().getDrawable(R.drawable.smartplud_tab));
spec2.setContent(R.id.control);

mytabhost.addTab(spec1);
mytabhost.addTab(spec2);

In my mainactivity.java , setcontentview(R.id.main).

setContentView(R.layout.activity_main);

In tab1.xml i have a Imagebutton with id 'btn_add'.When i click this Imagebutton i need to generate a textview dynamically in the same tab1.xml from mainactivity.java instead of activity_main.xml

IamgeButton add_btn=(ImageButton)findViewById(R.id.btn_add);
add_btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view)
{
linearlayout = new LinearLayout(getApplicationContext());
LayoutParams LLParams = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
linearlayout.setLayoutParams(LLParams);
TextView txt_roomDetails=new TextView(getApplicationContext());

txt_roomDetails.setText("abcdefghi");
linearlayout.addView(txt_roomDetails);

setContentView(linearlayout);
}
});


I know if I give "getApplicationContext()" that will be created in activity_main.xml.........But i need in tab1.xml just below btn_add without using any intent.Please help....any solutions
Posted
Comments
Sandeep Londhe 10-Oct-14 16:32pm    
use fragment instead of Activity

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900