【发布时间】:2012-06-20 17:22:44
【问题描述】:
在我的应用程序中,有一个 Activity 包含很多视图(editText-fields,...)。因为屏幕太小,无法容纳所有视图。因此,我想使用一个 ExpandableList ,其中包含所有按语义分组(作为布局)的视图来列出项目。
有没有简单的方法来完成这项工作?实现适配器似乎有点复杂,因为列表应该只包含“静态”视图。
这样的东西会很好:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ExpandableListView lv = (ExpandableListView) findViewById(R.id.explist);
lv.addItem(findViewById(R.id.linearlayoutitemone);
lv.addItem(findViewById(R.id.linearlayoutitemtwo);
EditText et = (EditText) lv.getItem(1).findViewById(R.id.etBirthdate);
et.setText("01.01.1970");
(....)
}
【问题讨论】:
-
使用适配器实际上更容易,如果不这样做,您最终可能会编写与在适配器中编写的代码相同的代码 + 一些额外内容(如 for 循环)。只需为自定义适配器找到一个好的模板,然后更改您必须要做的事情。
标签: android android-layout expandablelistview