2012-03-01 55 views
1

在我的应用程序中,用户旋转旋转木马。在选定的项目上,我需要为每个项目显示一个单独的xml视图。传送带始终位于底部,视野清晰可见。我认为有比使用碎片更好的方法。有任何想法吗?以下代码目前不起作用,但我认为充气机可能是要走的路,但要完成它却困扰着我。 case0后有case1-case5。显示多个不含片段的xml视图

carousel.setOnItemSelectedListener(new OnItemSelectedListener(){ 

     public void onItemSelected(CarouselAdapter<?> parent, View view, 
       int position, long id) { 



      switch(position){ 
      case 0: 
       final View firstview; 
       LayoutInflater inflater = (LayoutInflater) getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
       firstview = inflater.inflate(R.layout.selected_item, null); 
       break; 
      case 1: 

回答

2

万一别人运行到这个问题,我解决它:

LayoutInflater inflater = (LayoutInflater) CarouselActivity.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      LinearLayout inflateView = (LinearLayout) findViewById(R.id.InflateParent); 
      View nextView = null; 

      switch(position){ 
      case 0: 
       System.out.println("Case 0"); 
       inflateView.removeAllViews(); 
       nextView = inflater.inflate(R.layout.nextview, null); 
       inflateView.addView(nextView);