自定义可扩展列表Android

时间:2012-11-07 16:09:32

标签: android list customization

这就是我的应用程序看起来像使用可扩展的listview从数据库读取数据然后显示它,范围是3个月或12周!现在我想要的是只显示每周的内容!!我不想显示WEEK标签!例如,如果在这12周内有任何数据我们将显示它(但只有日标签和数据描述),但如果没有,我们想要什么都不显示!! (不显示周数!)我也想禁用每个项目的折叠。

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 个答案:

答案 0 :(得分:1)

您正在处理的两个问题:

(1)不显示没有条目的周数的组视图

为此,我建议修改您的组游标查询,使其不返回带有“空”周条目的游标。

(2)不允许用户折叠组

出于同样的目的,我实施了OnGroupClickListener来拦截群组点击,并且基本上不对其进行任何操作。这允许我控制组展开或折叠的时间。这是我的听众实现:

/**
 * 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);
    }