2012-11-07 80 views
0

这就是我的应用程序使用可扩展列表视图从数据库中读取数据然后显示它的范围,范围为3个月或12周!现在我想要的是只显示每周的内容!我不想显示WEEK标签!例如,如果在这12个星期内有任何数据,我们会显示它(但只是标有日期标签和数据说明),但如果不是,我们不想显示任何内容! (不显示星期!),我也想禁用每个项目的崩溃。自定义可扩展列表Android

enter image description here

这是我的适配器你正在处理

public class MyCareHeaderExpandableListAdapter extends MyCareExpandableListAdapter { 

public MyCareHeaderExpandableListAdapter(Context context) { 
    super(context); 
} 
//-------------------------------------------------------------------- 

@Override 
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
    //Log.d("getChildView", "getChildView " + groupPosition); 
    //View view = adapter.getView(childPosition, convertView, parent); 
    Item item = getChild(groupPosition, childPosition); 
    return setContentView(R.layout.expandable_list_item, convertView, item); 
} 
//-------------------------------------------------------------------- 
@Override 
public long getChildId(int groupPosition, int childPosition) { 
    int id = ((ScheduleItem)m_childrens.get(groupPosition).getItem(childPosition)).getID(); 
    return id; 
} 
//-------------------------------------------------------------------- 

/** 
* This function is called to generate the view for the groups. 
*/ 
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
    String name[] = getGroup(groupPosition); 

    // Generating header 
    // A header has no child, and begins the name with "Week" 
    //if (getChildrenCount(groupPosition) == 0 && (name[1] == null)) { 
    if (name[1] == null) { 
     convertView = m_inflater.inflate(R.layout.expandable_list_week, null); 
     TextView textView = (TextView)convertView.findViewById(R.id.txtHeader); 
     Font.setToView(textView, Font.BOLD); 
     textView.setText(name[0]); 
    } 
    // Generating group name 
    else { 
     //Log.d("getGroupView", name); 
     convertView = m_inflater.inflate(R.layout.expandable_list_group, null); 
     TextView textView = (TextView)convertView.findViewById(R.id.txtDay); 
     textView.setText(name[0]); 
     Font.setToView(textView, Font.BOLD); 

     TextView textView2 = (TextView)convertView.findViewById(R.id.txtDate); 
     textView2.setText(name[1]); 
     Font.setToView(textView2, Font.BOLD); 
    } 
    return convertView; 
} 

回答

1

两个问题:

(1)不显示,没有条目

为周组视图这个,我建议修改你的组游标查询,这样它不会返回一个游标的“空”星期条目。

(2)不允许用户坍塌组

为了同样的目的,我实现了​​拦截组的点击,基本上什么都不做吧。这使我可以控制组何时展开或折叠。在这里我的监听器实现:

/** 
* Only purpose here is to intercept taps on the header rows and ignore them 
* (avoid expandable list view adapter from expanding/collapsing). 
*/ 
@Override 
public boolean onGroupClick(ExpandableListView parent, View v, 
     int groupPosition, long id) { 
    return true; 
} 

编辑:

要让所有的群体扩展:

int groupCount = myCursorTreeAdapter.getGroupCount(); 
    for (int i = 0; i < groupCount; i++) { 
     myExpandableListView().expandGroup(i); 
    } 
+0

为第二个我已经尝试过这...这适用于对群体禁用触控但问题是,它只显示今天的孩子(事件)!对于其他日子组是封闭的,当然,我们无能为力,因为它已经被禁用了! ,因为你可以看到我的第一篇文章中的图片!它显示今天的事件,但其他的事件我们看不到! –

+1

让我看看我是否理解正确:(1)你不想看到周数,(2)你只想显示日期(天),当该日期至少有一个条目,(3)所有天条目应显示条目。我有没有得到那个权利? – bobnoble

+0

是的,它正是我想要的 –