添加ExpandableListView和其他元素的标签 [英] Add ExpandableListView to a tab with other elements
问题描述
我发展与标签的应用程序。在其中一个选项卡, 我有两个的EditText字段和几个按钮。我想补充一个ExpandableListView 到标签上,下方的元件的其余部分。
I am developing an app with tabs. On one of the tabs, I have two EditText fields and a couple of buttons. I want to add an ExpandableListView to the tab, below the rest of the elements.
我的问题是,当前类扩展了活动。所有我发现的例子延伸ExpandableListActivity,但我不能为同一类扩展两者。
My problem is that the current class extends Activity. All the example I've found extend ExpandableListActivity, but I can't extend both for the same class.
我如何添加此列表的标签?我已经在XML文件中添加了一个ExpandableListView元素,但每当我运行它,它不会显示出来。我知道我需要绑定的视图的一些数据,但我怎么去这样做? 谢谢你。
How can I add this list to the tab? I've added an ExpandableListView element in the XML file, but whenever I run it, it doesn't show up. I understand that I need to bind the view to some data, but how do I go about doing this? Thank you.
下面是我的课code:
Here is my class code:
公共类DirectionsTab扩展活动 { 私人按钮clear_btn; 私人按钮go_btn; 私人的EditText origin_txt; 私人的EditText dest_txt;
public class DirectionsTab extends Activity { private Button clear_btn; private Button go_btn; private EditText origin_txt; private EditText dest_txt;
公共无效的onCreate(包savedInstanceState) { super.onCreate(savedInstanceState); 的setContentView(R.layout.directions_tab);
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.directions_tab);
// initialize views and onClick event handler
origin_txt = (EditText)findViewById(R.id.origin_txt);
dest_txt = (EditText)findViewById(R.id.dest_txt);
clear_btn = (Button)findViewById(R.id.clear_btn);
// clear all text fields and return focus to dest_txt
clear_btn.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
origin_txt.setText("");
dest_txt.setText("");
origin_txt.requestFocus();
}
});
} // end public void onCreate(Bundle savedInstanceState)
} //结束公共类DirectionsTab扩展活动
} // end public class DirectionsTab extends Activity
和XML:
<TextView
android:id="@+id/dest_lbl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/origin_txt"
android:text="Destination"
/>
<EditText
android:id="@+id/dest_txt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/dest_lbl"
/>
<ExpandableListView
android:id="@+id/listView"
android:layout_below="@+id/dest_txt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
/>
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ ID / dest_txt
机器人:layout_alignParentRight =真
机器人:layout_marginLeft =10dip
机器人:layout_marginTop =10dip
机器人:文本=清除
/>
机器人:layout_toLeftOf =@ ID / clear_btn
机器人:layout_alignTop =@ ID / clear_btn
机器人:文本=去!
/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/dest_txt"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:layout_marginTop="10dip"
android:text="Clear"
/>
android:layout_toLeftOf="@id/clear_btn"
android:layout_alignTop="@id/clear_btn"
android:text="Go!"
/>
推荐答案
我得到这个!如果任何人有问题,这一点,一定要遵循以下步骤:
I got this! If anyone's having problems with this, make sure you follow these steps:
- 复制并粘贴<一href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/ExpandableList3.html"相对=nofollow> ExpandableList3 例子(位于ApiDemos项目从Samples文件夹在你的Android SDK)。这是如何建立一个列表,只是一个很好的例子。
- 请你的类继承自ExpandableListActivity
-
建立在XML布局文件如下:
- Copy and paste ExpandableList3 example (located in ApiDemos project from Samples folder in your Android SDK). This is just a good example of how to set up a list.
- Make your class inherit from ExpandableListActivity
Create the following in your XML layout file:
<ExpandableListView
android:id="@android:id/list"
android:layout_below="@+id/go_btn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
/>
这是非常重要的,你看到的上面,否则任何方法都行不通的ID属性相匹配。这个小细节浪费了大量的时间对我来说,发现整齐的座位作为一个小细节在Android文档。
It is VERY important that the ID property matches what you see above, otherwise nothing will work. This little detail wasted plenty of hours for me, and was discovered seating neatly as a small detail in the Android docs.
这篇关于添加ExpandableListView和其他元素的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!