如何将可扩展列表放在ActionBar选项卡片段中?

时间:2013-05-29 11:18:00

标签: android fragment expandablelistview

嗨,我在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?

2 个答案:

答案 0 :(得分:0)

如果我理解正确,您应该只在您的片段布局中放置ExpandableList,以获取actionBar选项卡片段的特定布局。这应该真的很容易...... 你能给我们提供一些代码吗?

答案 1 :(得分: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;
}