2013-05-29 58 views
0

喜即時通訊在Android的有點小白,所以我希望有人能幫助我 i have an actionBar tab fragment, and i wanted to make a expandable list with data and put it on the fragment, i´ve been searching online but the examples are too complex and dont match my situation i just want a simple expandable list, can anyone help?如何在ActionBar選項卡片段中放置可擴展列表?

+0

請詳細說明你的問題。任何代碼片段或您的嘗試邏輯表示讚賞。 –

回答

0

如果我理解正確的話,你應該只把ExpandableList你的片段佈局的動作條標籤片段特定佈局內。這實際上應該很容易... 你能給我們提供一些代碼嗎?

0

這是我的課tabActionBarActivity:

public class TabActionBarActivity extends Activity { 

String contextoId; 
String BuId; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_tab_action_bar); 

    ActionBar actionBar = getActionBar(); 
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); 

    String label1 = getResources().getString(R.string.label1); 
    Tab tab = actionBar.newTab(); 
    tab.setText(label1); 

    TabListener<Tab1Fragment> tl = new TabListener<Tab1Fragment>(this, label1, Tab1Fragment.class); 

    tab.setTabListener(tl); 
    actionBar.addTab(tab); 


    String label2 = getResources().getString(R.string.label2); 
      tab = actionBar.newTab(); 
      tab.setText(label2); 
      TabListener<Tab2Fragment> tl2 = new TabListener<Tab2Fragment>(this, label2, Tab2Fragment.class); 
      tab.setTabListener(tl2); 
      actionBar.addTab(tab); 


      BuId = getIntent().getExtras().getString("BUId"); 
      contextoId = getIntent().getExtras().getString("CId"); 
      Log.i("BUIdTabFrag", BuId); 







private class TabListener<T extends Fragment> implements 
      ActionBar.TabListener { 
     private Fragment mFragment; 
     private final Activity mActivity; 
     private final String mTag; 
     private final Class<T> mClass; 


     public TabListener(Activity activity, String tag, Class<T> clz) { 
         mActivity = activity; 
         mTag = tag; 
         mClass = clz; 
        } 



     @Override 
     public void onTabReselected(Tab tab, FragmentTransaction ft) { 
      // TODO Auto-generated method stub 

     } 




     @Override 
     public void onTabSelected(Tab tab, FragmentTransaction ft) { 
      // Check if the fragment is already initialized 
         if (mFragment == null) { 
          // If not, instantiate and add it to the activity 
          mFragment = Fragment.instantiate(mActivity, mClass.getName()); 
          ft.add(android.R.id.content, mFragment, mTag); 
         } else { 
          // If it exists, simply attach it in order to show it 
          ft.attach(mFragment); 
         } 


     } 




     @Override 
     public void onTabUnselected(Tab tab, FragmentTransaction ft) { 
      if (mFragment != null) { 
           // Detach the fragment, because another one is being attached 
           ft.detach(mFragment); 
          } 


     } 




} 

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    // Inflate the menu; this adds items to the action bar if it is present. 
    getMenuInflater().inflate(R.menu.tab_action_bar, menu); 
    return true; 
} 

相關問題