问题描述
我试图用ExpandableListActivity在我的计划,但我已经继承了班上TabActivity。我不能做多重继承,我需要在我的程序同时使用ExpandableListView和标签。
我检查了谷歌的code为ExpandableListView这里的.
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 ExpandableListView and the Tabs in my program.I checked Google's code for the ExpandableListView here http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList1.html.
但在这里他们继承它,因为我已经继承了TabActivity在我的课,我不能做ExpandableListActivity。
But here they are inheriting the ExpandableListActivity which I cannot do as I have already inherited TabActivity in my class.
我知道我可以使用的ListView没有在我的类继承ListActivity。我可以做的ExpandableListView类也一样吗?如果是这样,那么任何人都可以请我提供任何样品code使用ExtendableListView没有继承的活动?
I am aware that I can use ListView without inheriting ListActivity in my class. Can I do the same for the ExpandableListView class also ? If so, then can anyone please provide me with any sample code to use ExtendableListView without inheriting the activity ?
推荐答案
您可以扩展ExpandableListView自定义视图,并使用它里面TabActivity。
You can have a custom view that extends ExpandableListView and use it inside the TabActivity.
可扩展列表视图
public class CustomExpListView extends ExpandableListView{
/** Your code **/
}
托管选项卡主要活动
Main Activity that hosts the tabs
public class MyTabActivity extends TabActivity{
private TabHost tabhost;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
tabHost = getTabHost();
tabHost.addTab(tabHost
.newTabSpec("Tab 1")
.setIndicator("Tab 1",
this.getResources().getDrawable(
R.drawable.tab_icon))
.setContent(new Intent(this, Tab1.class)));
/** Further code**/
}
}
有关与EXP列表的标签XML布局文件(制表1)
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"/>
在类的EXP列表标签
CustomExpListView custExpListView = (CustomExpListView) this
.findViewById(R.id.exp_list_view);
您还可以延长监听器和自定义。
You can also extend the listeners and customize it.
希望它帮助!
这篇关于Android的ExpandableListActivity和TabActivity在同一级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!