2013-03-28 66 views
0

---下面更新---機器人slidingmenu和expandablelistview不工作

我有表示ExpandableListView(ELV)的問題的SlidingMenu片段的內部。該片段加載正常,如果我使用ListView沒有問題。我已經實現了一個自定義適配器來加載組和子項目的視圖,並且當ELV在正常活動中加載時,一切都按預期工作。

我一直在調試它的年齡和實際的ELV繪製(我將背景設置爲全紅色,並且顯示了我的預期位置),但組和子元素未繪製。當帶有slidingmenu的活動被加載時(如getGroupView),將調用適配器中的所有相關方法。 任何人都可以幫助我獲得實際的小組和孩子們在SlidingMenu內部展示嗎?

這是我ELV佈局XML:

<ExpandableListView 
    android:id="@+id/trackermenutypes_explist" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:transcriptMode="disabled" 
    android:layout_gravity="right" 
    android:layout_margin="15dp" 
/> 

方法在適配器獲得視圖:

@Override 
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.listitem_typegroup, null); 
     } 
     ((TextView) convertView.findViewById(R.id.listitem_typegroup_name)).setText(mTypeGroups.get(groupPosition).getName()); 
     Log.d(TAG, "Returning GroupView for group \"" + mTypeGroups.get(groupPosition).getName() + "\""); 
     return convertView; 
    } 

    @Override 
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { 
     if (convertView == null) { 
      convertView = mInflater.inflate(R.layout.listitem_type, null); 
     } 
     ((TextView) convertView.findViewById(R.id.listitem_type_name)).setText(mGroupedTypes.get(groupPosition).get(childPosition).getName()); 
     Log.d(TAG, "Returning ChildView for type \"" + mGroupedTypes.get(groupPosition).get(childPosition).getName() + "\""); 
     return convertView; 
    } 

我的片段onActivityCreated方法(在底部註釋掉工作的ListView) :

@Override 
public void onActivityCreated(Bundle savedInstanceState) { 
    Log.d(TAG, "onActivityCreated"); 
    super.onActivityCreated(savedInstanceState); 
    mContext = (TrackerActivity) getActivity(); 
    //lTypesList = getListView(); 
    lExpList = (ExpandableListView)mContext.findViewById(R.id.trackermenutypes_explist); 
    mPrefs = PreferenceManager.getDefaultSharedPreferences(mContext); 

    mTypeGroupDataSource = new TypeGroupDataSource(mContext); 
    mTypeGroupDataSource.open(); 
    mTypeGroups = mTypeGroupDataSource.getAllTypeGroups(); 

    mTypeDataSource = new TypeDataSource(mContext); 
    mTypeDataSource.open(); 
    mTypes = mTypeDataSource.getTypesOfClub(DataService.DEFAULT_CLUB_ID); 
    mTypes.addAll(mTypeDataSource.getTypesOfClub(mPrefs.getLong(DataService.PREFS_CLUB_ID, -1))); 

    TypeAdapter typeAdapter = new TypeAdapter(mContext, mTypeGroups, mTypes); 
    lExpList.setAdapter(typeAdapter); 

    lExpList.setOnChildClickListener(new OnChildClickListener() { 
     @Override 
     public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { 
      mContext.updateCurrentType(id); 
      mContext.getSlidingMenu().toggle(); 
      return true; 
     } 
    }); 
    Log.d(TAG, "Expanding " + typeAdapter.getGroupCount() + " groups"); 
    for (int i = 0; i < typeAdapter.getGroupCount(); i++){ 
     lExpList.expandGroup(i); 
    } 
    //TODO Implement "Add Type" feature 
    /*ArrayAdapter<TypeData> typeAdapter = new ArrayAdapter<TypeData>(mContext, R.layout.listitem_type, R.id.listitem_type_name, mTypes); 
    setListAdapter(typeAdapter); 

    lTypesList.setOnItemClickListener(new OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View item, int position, long id) { 
      mContext.updateCurrentType(position); 
      mContext.getSlidingMenu().toggle(); 
     } 
    });*/ 
} 

--- UPDATE --- 我想通了一種方法讓它繪製組和項目,通過使我的片段爲ListFragment並使用setList來代替。從現在開始,這是一種破解。 setAdapter不能用於我的自定義BaseExpandableListAdapter。當我在實際列表(從findViewByID)調用它時,它不會對觸摸事件做出反應。所以現在我有一個漂亮的名單,不能使用。有什麼建議麼?

回答

0

我似乎無法找到任何答案,讓ExpandableListView顯示在SlidingMenu中而沒有「黑客」並使用ListFragment - 導致無法使用片段上的stadderard setAdapter來設置ExpandableListAdapter 。如果可用,也許ExpandableListFragment可以解決問題。

對觸摸事件沒有反應的更新的錯誤是我自己的錯 - 我在適配器isChildSelectable方法中返回false。