1

我使用此代码创建 n 个选项卡:

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);

这是我的 ListViewActivity。它获取对象的 ArrayList 并使用我的自定义 MyCustomBaseAdapter 填充似乎工作正常的列表。

 @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();
          }  
         });
 }

问题是它填充选项卡并按下每个新选项卡填充字段就好了,但是当您返回上一个选项卡时它不会变回,内容仍然存在。它也以一种奇怪的方式进行操作,它不会从第二个选项卡转到第一个选项卡,它在第三个到第二个选项卡之间切换得很好,如果你转到第四个选项卡,那么它的内容会保留在所有选项卡中。

知道我应该在哪里寻找问题或替代解决方案以拥有一个填充列表并具有“临时”选项卡的类吗?

4

0 回答 0