꽤 이상한 문제가 있습니다. 내 논리는 간단합니다. 내 응용 프로그램은 기본 응용 프로그램 탐색에 NavigationDrawer
을 사용하며, 사용 가능한 옵션의 복잡성으로 인해 ExpandableListViev
을 사용하여 일부 탐색 항목을 중첩합니다.ExpandableListView 및 NavigationDrawer
문제가 있습니까? Simple too : 서랍에 아이템 목록이로드됩니다. 그러나 그들은 아이들을 보여주기 위해 확장하지 않습니다.
질문 확장되지 않는 이유가 있습니까? 다른 UI 위젯을 사용해야합니까? 일부 주
: 나는 다른 작업에 동일한 코드를 추가, 대신 서랍에 ExpandableListViev
호스팅, 나는 그것이 유일한 요소로 간단한 LinearLayout
에 추가했고, 그것은 이 잘 작동 하는가 . 활동에 대한
내 레이아웃 :
이<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ExpandableListView
android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/secondary_color_holo"/>
</android.support.v4.widget.DrawerLayout>
활동 코드 :
private DrawerLayout mDrawerLayout;
private ExpandableListView mDrawerList;
private ExpandableDrawerAdapter mDrawerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ExpandableListView) findViewById(R.id.left_drawer);
// set up the drawer's list view with items and click listener
mDrawerAdapter = new ExpandableDrawerAdapter(this);
mDrawerList.setAdapter(mDrawerAdapter);
mDrawerList.setOnGroupClickListener(new DrawerGroupClickListener());
mDrawerList.setOnChildClickListener(new DrawerChildClickListener());
}
그리고 마지막으로 아주 간단한 어댑터 :
public class ExpandableDrawerAdapter extends BaseExpandableListAdapter {
private static final int CAMPAIGNS = 0;
private static final int CONVERSIONS = 1;
private static final int MYACCOUNT = 2;
private LayoutInflater mInflater;
private String[] mainNavItems, campaignNavItems, myAccountNavItems;
public ExpandableDrawerAdapter (Activity context) {
this.mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
this.mainNavItems = context.getResources().getStringArray(R.array.main_nav_items);
this.campaignNavItems = context.getResources().getStringArray(R.array.campaigns_nav_items);
this.myAccountNavItems = context.getResources().getStringArray(R.array.my_account_nav_items);
}
public Object getChild(int groupPosition, int childPosition) {
switch (groupPosition) {
case CAMPAIGNS:
return campaignNavItems[childPosition];
case MYACCOUNT:
return myAccountNavItems[childPosition];
default:
return "";
}
}
public long getChildId(int groupPosition, int childPosition) {
return childPosition;
}
public View getChildView(final int groupPosition, final int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.drawer_child_list_item, null);
}
TextView childText = (TextView) convertView.findViewById(R.id.drawer_child_list_item_text);
childText.setText((String) getChild(groupPosition, childPosition));
return convertView;
}
public int getChildrenCount(int groupPosition) {
switch (groupPosition) {
case CAMPAIGNS:
Constants.logMessage("Children for group position: " + groupPosition + " are: " + campaignNavItems.length);
return campaignNavItems.length;
case CONVERSIONS:
Constants.logMessage("Children for group position: " + groupPosition + " are: " + 0);
return 0;
case MYACCOUNT:
Constants.logMessage("Children for group position: " + groupPosition + " are: " + myAccountNavItems.length);
return myAccountNavItems.length;
default:
return 0;
}
}
public Object getGroup(int groupPosition) {
return mainNavItems[groupPosition];
}
public int getGroupCount() {
return mainNavItems.length;
}
public long getGroupId(int groupPosition) {
return groupPosition;
}
public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.drawer_list_item,
null);
}
TextView groupText = (TextView) convertView.findViewById(R.id.drawer_list_item_text);
groupText.setText((String) getGroup(groupPosition));
return convertView;
}
public boolean hasStableIds() {
return true;
}
public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}
명백한 질문은 아이들을위한 배열에 값을 가졌을 것입니다 (나는 당신이 가지고 있다고 생각합니다 :)). 나는 당신이 당신의'ExpandableListView'에'OnGroupClickListener'을 설정했다는 것을 알고 있습니다, 당신이 그 리스너의'onGroupClick()'콜백으로부터'false'를 반환하기를 바랍니다. 그렇지 않으면 반환 값으로 붕괴/확장 이벤트를 차단할 것입니다. 'true'(이미 이벤트를 처리 했으므로 다른 작업이 필요하지 않음을 의미). – Luksprog
흠, 문서가 너무 명확하지 않으면 true를 반환하면 기본 축소 및 확장이 차단됩니다. 서랍 외부에서 동일한 논리를 적용했는데 이상하게도 작동했습니다. 나는 집에 있지 않지만, 내 청취자 모두에게 사실로 돌아 오기 때문에 내 문제에 대한 올바른 해결책이 될 것 같다. 원하면 대답으로 게시하고 집에 돌아와 거짓 답을 테스트하면 대답을 수락 할 수 있습니다. –
각 항목이 확장/축소됩니까? 아니면 확장 가능한 항목과 간단한 클릭 가능한 항목으로 남아있는 항목이 있습니까? – AlleyOOP