Reputation: 622
Im new To StackOverFlow and my prob is im just creating an app which has tabs in it and i want to add the same layout content say layout.xml to all the tabs and the layout.xml has a button within it and it has some textboxes. Whenever the button is pressed i want to calculate a value using the textbox content. Im inflating the layout.xml for each new tab but onClickListener() is not working for tabs... Can any one Help Me ... Please....
TabSpec spec = th.newTabSpec("tag1");
spec.setContent(new TabHost.TabContentFactory() {
public View createTabContent(String tag) {
// TODO Auto-generated method stub
final View sem = getLayoutInflater().inflate(
R.layout.semester, null);
Button Add = (Button) findViewById(R.id.bAdd);
Add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View paramView) {
// TODO Auto-generated method stub
counter++;
LinearLayout A = createNewSubject();
((ViewGroup) sem).addView(A);
}
});
return sem;
This is my Code to Add a New Tab....
Upvotes: 0
Views: 1662
Reputation: 140
I think the only problem is with given below line
Button Add = (Button) findViewById(R.id.bAdd);
you have to use this
Button Add = (Button)sem.findViewById(R.id.bAdd);
Upvotes: 2