Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Android
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Android
Multiple level expandable lists
Gary Down
Greenhorn
Posts: 11
posted 10 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Being new to this (android and
java
) I have hit a wall. The first level list displays but appears to be inactive (nothing happens when clicked).
The source and the XML files are below.
Any help will be appreciated.
Cheers,
Gary.
Activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.newShop.MainActivity" > <ExpandableListView android:id="@+id/TopLevel" android:layout_width="match_parent" android:layout_height="fill_parent"> </ExpandableListView> <ExpandableListView android:id="@+id/MiddleLevel" android:layout_width="match_parent" android:layout_height="fill_parent"> </ExpandableListView> <ExpandableListView android:id="@+id/BottomLevel" android:layout_width="match_parent" android:layout_height="fill_parent"> </ExpandableListView> </RelativeLayout>
all_levels_text
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context="com.newShop.MainActivity" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="10dp"> <TextView android:id="@+id/leveltextitem" android:layout_width="wrap_content" android:layout_height="wrap_content"/> </LinearLayout>
package com.newShop; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.BaseExpandableListAdapter; import android.widget.ExpandableListView; import android.widget.ExpandableListView.OnGroupExpandListener; import android.widget.TextView; import android.util.Log; public class MainActivity extends Activity { ExpandableListView topLevelListView; private int[] groupsForEachLevel = {3, 3, 3, 3, 3, 3}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); topLevelListView = (ExpandableListView) findViewById(R.id.TopLevel); ShopListAdapter bla = new ShopListAdapter(MainActivity.this, 0); topLevelListView.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { for (int i = 0; i < groupsForEachLevel[0]; i++) { if (i != groupPosition) { topLevelListView.collapseGroup(i); } } } }); topLevelListView.setAdapter(bla); } public class ShopListView extends ExpandableListView { public ShopListView(Context context) { super(context); } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { widthMeasureSpec = MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST); heightMeasureSpec = MeasureSpec.makeMeasureSpec(1000, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } } public class ShopListAdapter extends BaseExpandableListAdapter { private ShopListView nextLevelListView; private LayoutInflater layoutInflater; private int level; private int groupsInThisLevel; private int childCount; public ShopListAdapter(Activity context, int level) { layoutInflater = LayoutInflater.from( context ); this.level = level; this.groupsInThisLevel = groupsForEachLevel[level]; if (level == groupsForEachLevel.length - 1) { this.childCount = 0; } else { this.childCount = 1; } } @Override public Object getChild(int groupPosition, int childPosition) { return childPosition; } @Override public long getChildId(int groupPosition, int childPosition) { return childPosition; } @Override public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { Log.w("****", "getChildView"); Log.w("****", "getChildView level " + Integer.toString(level)); Log.w("****", "getChildView group " + Integer.toString(groupPosition)); Log.w("****", "getChildView child " + Integer.toString(childPosition)); Log.w("****", "getChildView length " + Integer.toString(groupsForEachLevel.length)); Log.w("****", "getChildView last " + Boolean.toString(isLastChild)); int nextLevel = this.level + 1; if (nextLevel < groupsForEachLevel.length) { Log.w("****", "new level >>" + Integer.toString(nextLevel)); nextLevelListView = (ShopListView) findViewById(R.id.MiddleLevel); ShopListAdapter bla = new ShopListAdapter(MainActivity.this, nextLevel); nextLevelListView.setAdapter(bla); nextLevelListView.setOnGroupExpandListener(new OnGroupExpandListener() { @Override public void onGroupExpand(int groupPosition) { for (int i = 0; i < getGroupCount(); i++) { if (i != groupPosition) { nextLevelListView.collapseGroup(i); } } } }); } return nextLevelListView; } @Override public int getChildrenCount(int groupPosition) { return this.childCount; } @Override public Object getGroup(int groupPosition) { return 0; } @Override public int getGroupCount() { return this.groupsInThisLevel; } @Override public long getGroupId(int groupPosition) { return groupPosition; } @Override public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) { Log.w("****", "getGroupView - isexpanded " + Boolean.toString(isExpanded)); Log.w("****", "getGroupView : level " + Integer.toString(level)); Log.w("****", "getGroupView : group " + Integer.toString(groupPosition)); View v = convertView != null ? convertView : layoutInflater.inflate(R.layout.all_levels_text, parent, false); TextView thisGroup = (TextView) v.findViewById(R.id.leveltextitem); thisGroup.setPadding(50 * (level + 1), 5, 5, 5); thisGroup.setText(Integer.toString(level) + " " + Integer.toString(groupPosition)); return v; } @Override public boolean hasStableIds() { return true; } @Override public boolean isChildSelectable(int groupPosition, int childPosition) { return true; } } }
It looks like it's time for me to write you a reality check! Or maybe a tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
error : Your content must have a ListView
Issue Dynamically Changing TextView
how to add main two button to my screen
Please, explain me how can I edit item of an arraylist
ListView empty
More...