我目前正在从事一个项目,在这个项目中,我需要以下内容:
- MainGroup 1 (Expandable)
- SubGroup 1 (Expandable)
- SubSubGroup 1 (Expandable)
- Child View
- Child View
- ...
- SubSubGroup 2 (Expandable)
- Child View
- Child View
- ...
- SubGroup 2 (Expandable)
- SubSubGroup 3 (Expandable)
- Child View
- ...
- SubSubGroup 4 (Expandable)
- Child View
- ...
- SubGroup 3 (Expandable)
- Child View
- ...
- MainGroup 2 (Expandable)
- ...最多是ExpandableListView在ExpandableListView内部,在ExpandableListView - so 3层的ExpandableListView中。
MainGroup只会持有其他ExpandableListView。SubGroup还将持有其他ExpandableListView,后者将永远只是ChildViews。(我想这两个可以用一个代替SubSubGroup)SubSubGroup会一直抱着ChildViews。我的问题是,我认为我不理解ExpandableListView如何布局它的孩子的基本原则。我看过像这这样的例子,但无法理解这些功能。
我尝试过在另一个组中作为子组添加一个ExpandableListView --但是如果您展开外部组中的一个,则某些东西不能工作,因为只有内部ExpandableListView的第一项是可见的。不过,我可以通过手动设置外部组容器的高度,使其足够大,以显示内部ExpandableListView中的所有项。要做到最优,当然应该在飞行中计算高度。
所以,想问一些更具体的问题:
ExpandableListView的“生命周期”(我指的是实例化、重用视图、展开/折叠侦听器),包括:。ExpandableListView是如何以及何时通知子节点被展开/折叠的?ExpandableListView如何知道有多少空间可以让所有的孩子适应到一个组容器中?
ExpandableListView和一些OnClickListeners混合我自己的解决方案相比,使用LinearLayouts创建上面的内容有多大的好处?编辑
对于我的最后一个问题,我可能会注意到,从1到20+ MainGroups可以有任何地方。
发布于 2011-12-02 06:53:47
首先,让我向您推荐GrepCode站点。它有Android类的来源。谢谢他们,我已经找到了AdapterViews的基本原理(我给了你一个ExpandableListView的链接,但是如果你不仅研究它,而且还研究它的班级家长,那就更好了)。
现在,你的问题和我的答案
ExpandableListView是如何以及何时通知子节点被展开/折叠的?
见方法handleItemClick(查看v,int位置,长id)
ExpandableListView如何知道有多少空间可以让所有的孩子适应到一个组容器中?
我没有很好地研究这个问题,但据我所知,它是由requestLayout()方法生成的。此外,我们发现一个可滚动视图不能嵌入到另一个可滚动视图中。(这是众所周知的错误:把ListView放在ScrollView中,把ListView放在ExpandableListView中)。
与使用一些ExpandableListView和一些OnClickListeners混合我自己的解决方案相比,使用LinearLayouts创建上面的内容有多大的好处呢?
AdapterViews更快。但是,即使对ExpandableListView来说,您的构造也太复杂了。您可以使用2种解决方案。
发布于 2011-11-29 08:25:54
您可能需要检查这项目。我还没试过,但我想值得一试。默认的ExpanadableListView是相当有限的,最初只支持两个级别。你可以利用它来让它支持更多的水平,但它会变得混乱。
发布于 2011-12-02 04:52:33
尽管这不是一个完整的解决方案,但它仍然是一个3层可扩展列表。所以你的风格就留给你了。
这是一堂课
package com.custom.nagee;
import android.app.ExpandableListActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
public class CustomemExpandible extends ExpandableListActivity{
LayoutInflater inflator;
boolean flag = true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
inflator = LayoutInflater.from(getApplicationContext());
setListAdapter(new MyAdapter());
}
@Override
public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {
if(flag){
v.findViewById(childPosition).setVisibility(View.VISIBLE);
flag = false;
return true;
}
v.findViewById(childPosition).setVisibility(View.GONE);
flag = true;
return true;
}
class MyAdapter extends BaseExpandableListAdapter{
@Override
public Object getChild(int groupPosition, int childPosition) {
return null;
}
@Override
public long getChildId(int groupPosition, int childPosition) {
return 0;
}
@Override
public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
LinearLayout linearLayout = (LinearLayout)inflator.inflate(R.layout.group, null);
linearLayout.getChildAt(1).setId(childPosition);
return linearLayout;
}
@Override
public int getChildrenCount(int groupPosition) {
return 2;
}
@Override
public Object getGroup(int groupPosition) {
return null;
}
@Override
public int getGroupCount() {
return 2;
}
@Override
public long getGroupId(int groupPosition) {
return 0;
}
@Override
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
return ((LinearLayout)inflator.inflate(R.layout.group, null));
}
@Override
public boolean hasStableIds() {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
}这是xml文件
group.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="@color/back"
android:layout_marginLeft="30dip"
android:text="DONE" >
</TextView>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="30dip"
android:visibility="gone" >
<TextView
android:id="@+id/editText2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="DONE">
</TextView>
<TextView
android:id="@+id/editText3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="DONE" />
<TextView
android:id="@+id/editText4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="DONE" />
</LinearLayout>
而这是在颜色文件夹下改变文字颜色,它的左,你甚至可以改变背景,以获得更好的外观。
back.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="#808080"/>
<item android:state_window_focused="false" android:color="#808080"/>
<item android:state_pressed="true" android:color="#808080"/>
<item android:state_selected="true" android:color="#000000"/>
<item android:color="#FF0000"/> <!-- not selected -->
</selector>希望它能成功..。
https://stackoverflow.com/questions/8293538
复制相似问题