Thursday 15 May 2014

java - Creating Tabs in Android -


I'm preparing an app that has more than 5 tabs to avoid redundancy, I use these tabs in a loop Want to make However, I have difficulty finding the syntax to attach the layout components to the tabs in the .java file. Here's the code:

  myTabs.setup (); (For Int i = 0; I <10; i ++) {TabCpec TabSpecs = ITAB. NEETBSSP ("tag" + I); TabSpecs.setContent (R.id.imageView + i); // error here myTabs.addTab (tabSpecs); }   

This may be a silly question but I hope that will help you.

Regards

Your problem is that you use the incorrect View ID only The id from the generated R class should be used. Read about and try to do the next: If you want to see different scenes, you need to create a list of visual IDs.

  ArrayList & lt; Integer & gt; List = New Arrestist & lt; Integer & gt; (); List.add (R.id.R.id.imageView1); List.add (R.id.R.id.imageView2); List.add (R.id.R.id.imageView3); For (int i = 0; i & lt; 2; i ++) {tab cpcc tabspx = ITabs. NEETBSPC ("tag" + I); TabSpecs.setContent (list.get (i)); MyTabs.addTab (tabSpecs); }   

But you should define all the images in the Resources folder. Also, you can put a look at this.

If you look at the example, you will see that Tab 1, Tab 2 and Tab 3 are defined in the id XML file so that your IDE can generate R class and include your identity in it. / P>

No comments:

Post a Comment