Android的ExpandableListActivity问题 [英] Android ExpandableListActivity issue
问题描述
我想自定义ExpandableList。我的问题是,我需要一个活动的按钮和扩展列表。我能做到这一点?我见过的所有例子,但所有扩展ExpandableListActivity不是活动中,我可以把所有的部件在一个活动。
任何帮助将是AP preciated。
I want to customize my ExpandableList. My issue is that I need a button and expandable list on single activity. Can I achieve that? I have seen all the examples but all extends ExpandableListActivity not the Activity in which I can put all the widgets in one activity. Any help would be appreciated.
推荐答案
据该的文档这个任务应该不会太辛苦了。
According to the documentation this task should not be too hard.
这是你必须做的第一件事就是创建一个新的XML文件来保存您的自定义布局。该文件应该被保存在你的RES /布局文件夹并命名为类似my_custom_expandable_list_view_layout.xml,它应该是这个样子:
the first thing that you will have to do is create a new xml file to hold your custom layout. The file should be saved in your res/layout folder and be named something like "my_custom_expandable_list_view_layout.xml", it should look something like this:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ExpandableListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"/>
<Button android:id="@id/my_button_id"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Click Me"/>
</LinearLayout>
这是布局文件的导入部分是,你包括ExpandableListView,并给它的机器人名单的ID。
The import part of that layout file is that you include an "ExpandableListView" and give it the id of "android"list".
这是你需要做的下一件事就是让你的活动知道你使用的是自定义布局通过调用<一个href=\"http://developer.android.com/reference/android/app/Activity.html#setContentView%28android.view.View%29\"相对=nofollow>的setContentView()在活动的onCreate()。该调用应该是这个样子。
The next thing that you will need to do is let your activity know that you are using a custom layout by calling setContentView() in your activities onCreate(). The call should look something like this
setContentView(R.layout.my_custom_expandable_list_view_layout);
在这一点上,你应该能够运行您的程序,看到一个大按钮在屏幕的底部。为了做这个按钮的东西,你需要通过调用来访问它的 findViewById()在活动像这样
Button myButton = (Button)findViewById(R.id.my_button_id);
一旦你的对象则myButton可以添加一个点击监听器或其他任何你想做的。您可以pretty太多只需添加新的东西到布局文件中添加其他任何你想要的。
Once you have that myButton object you can add a click listener or whatever else you would like to do. You can pretty much add anything else you want by just adding new things to the layout file.
这篇关于Android的ExpandableListActivity问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!