Skip to content Skip to sidebar Skip to footer

Android Expandablelistactivity And Tabactivity In Same Class

I am trying to use the ExpandableListActivity in my program but I have already inherited the TabActivity in my class. I cannot do multiple inheritance and I need to use both the Ex

Solution 1:

You can have a custom view that extends ExpandableListView and use it inside the TabActivity.

Expandable List View

publicclassCustomExpListViewextendsExpandableListView{
          /** Your code **/
     }

Main Activity that hosts the tabs

publicclassMyTabActivityextendsTabActivity{
    private TabHost tabhost;
    @OverrideprotectedvoidonCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          tabHost = getTabHost();
          tabHost.addTab(tabHost
                .newTabSpec("Tab 1")
                .setIndicator("Tab 1",
                        this.getResources().getDrawable(
                                R.drawable.tab_icon))
                .setContent(newIntent(this, Tab1.class)));

      /** Further code**/
    }
  }

XML Layout file for the tab with the exp list (Tab 1)

/**Other layout stuff goes here**/
<com.jmango.nexus.view.ProductListView
        android:layout_width="fill_parent"
                    android:layout_height="wrap_content" 
                    android:groupIndicator="@drawable/group_indicator"
        android:childIndicator="@drawable/child_indicator"
        android:cacheColorHint="#00000000" 
                    android:divider="#00BBFF"
                    android:childDivider="@android:drawable/divider_horizontal_dark"
        android:smoothScrollbar="true"
        android:id="@+id/exp_list_view"/>

In the class for the tab with the exp list

CustomExpListViewcustExpListView= (CustomExpListView) this
            .findViewById(R.id.exp_list_view);

You can also extend the listeners and customize it.

Hope it helps!

Post a Comment for "Android Expandablelistactivity And Tabactivity In Same Class"