1

I use this code to create n tabs :

TabHost tabs = (TabHost)findViewById(R.id.tabhost); 
     tabs.setup(mLocalActivityManager); 

     StateListDrawable[] drawables  = new StateListDrawable[hotel.categoryArray.length];

     for (int i = 0; i < hotel.categoryArray.length; i++){
         TabSpec spec1 = tabs.newTabSpec(hotel.categoryArray[i]);
         Intent intent = new Intent(this, ListViewActivity.class);
         Bundle b = new Bundle();
         b.putParcelableArrayList("Businesses", createArray(hotel.categoryArray[i], hotel.explore));
         intent.putExtras(b);
         spec1.setContent(intent); 
         TextView tab1 = new TextView(this);
         tab1.setText(hotel.categoryArray[i]);
         tab1.setGravity(android.view.Gravity.CENTER);
         tab1.setTextSize(14.0f);
         tab1.setTextColor(text);
         drawables[i] = new StateListDrawable();
         drawables[i].addState(selected, new ColorDrawable(selectedColor));
         drawables[i].addState(unselected, new ColorDrawable(defaultColor));
         tab1.setBackgroundDrawable(drawables[i]);
         spec1.setIndicator(tab1);
         tabs.addTab(spec1);
     }

     tabs.setCurrentTab(0);

And this is my ListViewActivity. It gets the ArrayList of objects and uses my custom MyCustomBaseAdapter to populate the list which seems to work fine.

 @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.list);

         Bundle bundle = this.getIntent().getExtras();
         ArrayList<Business> business = null;
         if(bundle!=null) {
             business = bundle.getParcelableArrayList("Businesses");
         }

         final ListView lv1 = getListView();
         lv1.setAdapter(new MyCustomBaseAdapter(this, business));

         lv1.setOnItemClickListener(new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
           Object o = lv1.getItemAtPosition(position);
           Business fullObject = (Business)o;
           Toast.makeText(ListViewActivity.this, "You have chosen: " + " " + fullObject.name, Toast.LENGTH_LONG).show();
          }  
         });
 }

The problem is it populates the tabs and pressing each new tab populates fields just fine, but when you go back to previous tab it does not change back, content remains. Also it does it in a strange manner, it does not go from 2nd tab to 1st, it switches fine between 3rd to 2nd, if you go to 4th its contents stays through all tabs then.

Any idea where should i look for the problem or alternative solution to have one class which populates the list and having "ad hoc" tabs?

user975869
  • 275
  • 1
  • 5
  • 12

0 Answers0