2012-11-07 54 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

是的,它正是我想要的 –