Help me to solve expandable list view problem..

Jay Park's picture

Recently I'm studying about multi level(4-level) expandable list view using ArrayList.
But there's some problem related getGroupCount function.
Parent Level's getGroupCount function works well, but two child level's getGroupCount function works bad.

I wanna implement listview like below.

. a
. a1
. a11
. a111
. a112
. a12
. a2
. b
. b1
. c

But the rusult of my source program is below. (a112 not shown)

. a
. a1
. a11
. a111
. a12
. a2
. b
. b1
. c

Is there anyone who cah help me to solve this problem?

my main.xml code is like below. (No other layout file exists.)

<?xml version="1.0" encoding="utf-8"?>

And my java code is like below.

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.LinearLayout.LayoutParams;

public class Studying_Sfonge extends Activity {
ExpandableListView explvlist;

private ArrayList oneLevel = new ArrayList();
private ArrayList twoLevel = new ArrayList();
private ArrayList threeLevel = new ArrayList();
private ArrayList fourLevel = new ArrayList();

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

oneLevel.add(0, new Place2("a"));
oneLevel.add(1, new Place2("b"));
oneLevel.add(2, new Place2("c"));

twoLevel.add(0, new Place2("a1"));
twoLevel.add(1, new Place2("b1"));
twoLevel.add(2, new Place2("a2"));

threeLevel.add(0, new Place2("a11"));
threeLevel.add(1, new Place2("a12"));

fourLevel.add(0, new Place2("a111"));
fourLevel.add(1, new Place2("a112"));

oneLevel.get(0).GroupPlace.add(0, twoLevel.get(0));
oneLevel.get(0).GroupPlace.add(1, twoLevel.get(2));
oneLevel.get(1).GroupPlace.add(0, twoLevel.get(1));
twoLevel.get(0).GroupPlace.add(0, threeLevel.get(0));
twoLevel.get(0).GroupPlace.add(1, threeLevel.get(1));
threeLevel.get(0).GroupPlace.add(0, fourLevel.get(0));
threeLevel.get(0).GroupPlace.add(1, fourLevel.get(1));

explvlist = (ExpandableListView) findViewById(R.id.ParentLevel);
explvlist.setAdapter(new ParentLevel());
}

public class ParentLevel extends BaseExpandableListAdapter {

public String getChild(int arg0, int arg1) {
return oneLevel.get(arg0).GroupPlace.get(arg1).getPlacename();
}

public long getChildId(int groupPosition, int childPosition) {
return 0;
}

public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {

CustExpListview SecondLevelexplv = new CustExpListview(Studying_Sfonge.this);
SecondLevelexplv.setAdapter(new SecondLevelAdapter(groupPosition,childPosition));

return SecondLevelexplv;
}

public int getChildrenCount(int groupPosition) {
return oneLevel.get(groupPosition).GroupPlace.size();
}

public Object getGroup(int groupPosition) {
return oneLevel.get(groupPosition);
}

public int getGroupCount() {
return oneLevel.size();
}

public long getGroupId(int groupPosition) {
return groupPosition;
}

public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {

TextView tv = new TextView(Studying_Sfonge.this);
tv.setText(oneLevel.get(groupPosition).getPlacename());
tv.setTextColor(Color.WHITE);
tv.setTextSize(20);
tv.setBackgroundColor(Color.BLACK);
tv.setPadding(60, 7, 7, 7);

return tv;
}

public boolean hasStableIds() {
return true;
}

public boolean isChildSelectable(int groupPosition, int childPosition) {
return true;
}
}

public class CustExpListview extends ExpandableListView {

int intGroupPosition, intChildPosition, intGroupid;

public CustExpListview(Context context) {
super(context);
}

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
widthMeasureSpec = MeasureSpec.makeMeasureSpec(960,
MeasureSpec.AT_MOST);
heightMeasureSpec = MeasureSpec.makeMeasureSpec(600,
MeasureSpec.AT_MOST);

super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}

public class SecondLevelAdapter extends BaseExpandableListAdapter {
private int childidx;
private int groupidx;

public SecondLevelAdapter(int groupPosition, int childPosition) {
// TODO Auto-generated constructor stub

this.groupidx = groupPosition;
this.childidx = childPosition;
}

public Object getChild(int groupPosition, int childPosition) {
return oneLevel.get(groupPosition).GroupPlace.get(childPosition);
}

public long getChildId(int groupPosition, int childPosition) {
return 0;
}

public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {

CustExpListview ThirdLevelAdapter = new CustExpListview(Studying_Sfonge.this);
ThirdLevelAdapter.setAdapter(new ThirdLevelAdapter(groupPosition,childPosition));

return ThirdLevelAdapter;
}

public int getChildrenCount(int groupPosition) {
return oneLevel.get(groupidx).GroupPlace.get(childidx).GroupPlace.size();
}

public Object getGroup(int groupPosition) {
return groupPosition;
}

public int getGroupCount() {
if (oneLevel.get(groupidx).GroupPlace.size()==0 )
return 0;
else
return 1;
}

public long getGroupId(int groupPosition) {
return groupPosition;
}

public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {

TextView tv = new TextView(Studying_Sfonge.this);

tv.setText(oneLevel.get(groupidx).GroupPlace.get(childidx).getPlacename());
tv.setTextColor(Color.WHITE);
tv.setTextSize(20);
tv.setPadding(90, 7, 7, 7);
tv.setBackgroundColor(Color.BLACK);

return tv;

}

public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}

public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}

public class ThirdLevelAdapter extends BaseExpandableListAdapter {
private int childidx;
private int groupidx;

public ThirdLevelAdapter(int groupPosition, int childPosition) {
// TODO Auto-generated constructor stub

this.childidx = childPosition;
}

public Object getChild(int groupPosition, int childPosition) {
return twoLevel.get(groupidx).GroupPlace.get(childidx);
}

public long getChildId(int groupPosition, int childPosition) {
return 0;
}

public View getChildView(int groupPosition, int childPosition,
boolean isLastChild, View convertView, ViewGroup parent) {

TextView tv = new TextView(Studying_Sfonge.this);
tv.setText( twoLevel.get(groupidx).GroupPlace.get(childidx).GroupPlace.get(childPosition).getPlacename() );
tv.setTextColor(Color.BLACK);
tv.setTextSize(20);
tv.setPadding(15, 5, 5, 5);
tv.setBackgroundColor(Color.GREEN);
tv.setLayoutParams(new ListView.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
return tv;
}

public int getChildrenCount(int groupPosition) {
return twoLevel.get(groupidx).GroupPlace.get(childidx).GroupPlace.size();
}

public Object getGroup(int groupPosition) {
return twoLevel.get(groupPosition);
}

public int getGroupCount() {
if (twoLevel.get(groupidx).GroupPlace.size()==0 )
return 0;
else
return 1;
}

public long getGroupId(int groupPosition) {
return groupPosition;
}

public View getGroupView(int groupPosition, boolean isExpanded,
View convertView, ViewGroup parent) {

TextView tv = new TextView(Studying_Sfonge.this);

tv.setText(twoLevel.get(groupidx).GroupPlace.get(childidx).getPlacename());
tv.setTextColor(Color.WHITE);
tv.setTextSize(20);
tv.setPadding(100, 7, 7, 7);
tv.setBackgroundColor(Color.BLACK);

return tv;
}

public boolean hasStableIds() {
// TODO Auto-generated method stub
return true;
}

public boolean isChildSelectable(int groupPosition, int childPosition) {
// TODO Auto-generated method stub
return true;
}
}

}

Taxonomy upgrade extras: 
Gabor Paller's picture

Your example is not complete, e.g. the Place2 class declaration is missing.
Could you export your project as an Eclipse archive and attach it to the post?

ujang sholahuddin's picture

Distributor plat besi hitam
Distributor plat besi hitam
undangan pernikahan bentuk tas
Distributor plat kapal besi baja
Agen besi beton interworld steel is
undangan pernikahan modern
Toko Plat Bordes Kembang
Distributor Pipa Besi baja Schedule Sch 40
Distributor besi cnp baja
jasa konstruksi baja
Harga plat besi hitam
Harga plat besi hitam
undangan pernikahan simple
undangan pernikahan biru
Harga plat kapal besi baja
Agen besi beton gunung garuda
undangan pernikahan biasa
jual laptop asus jual laptop asus
jual laptop asus murah jual laptop asus murah
Toko Plat Besi Hitam
Supplier Pipa Besi baja Schedule Sch 40
Harga besi cnp baja
www.pusatbesibaja.co.id
Jual plat besi hitam
Jual plat besi hitam
undangan pernikahan biasa
Jual plat kapal besi baja
Agen besi beton delcoprima
undangan pernikahan bahasa inggris islam
Toko Plat Kapal Bki Krakatau Steel
Agen Pipa Besi baja Schedule Sch 40
Jual besi cnp baja
www.pusatbesibaja.com
Supplier plat besi hitam
Supplier plat besi hitam
undangan pernikahan bagus
Supplier plat kapal besi baja
Agen besi beton cakra steel cs
undangan pernikahan cantik elegan
Toko Jual Besi Siku Baja
Toko Pipa Besi baja Schedule Sch 40
Supplier besi cnp baja
www.jualbesibajamurah.com
Toko plat besi hitam
Toko plat besi hitam
undangan pernikahan bermanfaat
Toko plat kapal besi baja
Agen besi beton bjku
undangan pernikahan akrilik
Toko Besi Unp Baja Profil Kanal
Jual Pipa Besi baja Schedule Sch 40
undangan pernikahan
undangan pernikahan amplop surat
Toko besi cnp baja
Supplier besi beton Sni Ulir Polos polos ulir
Agen plat besi hitam
Agen plat besi hitam
undangan pernikahan akrilik
Agen plat kapal besi baja
Agen besi beton Sni Ulir Polos
undangan pernikahan bentuk dompet
Toko Besi Cnp Profil Baja Gording
Harga Pipa Besi baja Schedule Sch 40
Agen besi cnp baja
Supplier besi beton sii
Pabrik plat besi hitam
Pabrik plat besi hitam
undangan pernikahan anti mainstream
Pabrik plat kapal besi baja
Agen besi beton ais
undangan pernikahan coklat
Toko Besi Hollow
Pabrik Pipa Besi baja Schedule Sch 40
Pabrik besi cnp baja
Supplier besi beton psi Ulir Polos
Distributor plat kapal besi baja
Distributor plat kapal besi baja
undangan pernikahan klub bola
Distributor besi siku baja
Agen besi beton
undangan pernikahan kalender
Toko Wiremesh
Distributor Pipa Besi baja Schedule sch 80
Distributor besi unp baja
Supplier besi beton perwira
Harga plat kapal besi baja
Harga plat kapal besi baja
undangan pernikahan cetak
Harga besi siku baja
undangan pernikahan modern
undangan pernikahan online
jasa konstruksi baja
undangan pernikahan coklat
Toko Besi Pipa Baja Schedule 80
Supplier Pipa Besi baja Schedule sch 80
Harga besi unp baja
Supplier besi beton PAS
Jual plat kapal besi baja
Jual plat kapal besi baja
Agen stainless steel
Jual besi siku baja
www.pusatbesibaja.co.id
undangan pernikahan arab
Toko Besi Pipa Baja Schedule 40
Agen Pipa Besi baja Schedule sch 80
Jual besi unp baja
Supplier besi beton master steel ms
Supplier plat kapal besi baja
Supplier plat kapal besi baja
Agen atap spandek
Supplier besi siku baja
www.pusatbesibaja.com
undangan pernikahan kalender
Toko Pipa Besi Hitam Medium
Toko Pipa Besi baja Schedule sch 80
Supplier besi unp baja
Supplier besi beton ksty
Toko plat kapal besi baja
Toko plat kapal besi baja
Agen baja ringan
Toko besi siku baja
www.jualbesibajamurah.com
undangan pernikahan custom
Toko Besi Wf
Jual Pipa Besi baja Schedule sch 80
Toko besi unp baja
Supplier besi beton krakatau steel
Agen plat kapal besi baja
Agen plat kapal besi baja
Agen bondek
Agen besi siku baja
Toko besi beton Sni Ulir Polos polos ulir
undangan pernikahan klasik
Toko Besi H beam
Harga Pipa Besi baja Schedule sch 80
Agen besi unp baja
Supplier besi beton jcac
Pabrik plat kapal besi baja
Pabrik plat kapal besi baja
Agen Plat kapal besi baja bki krakatau steel
Pabrik besi siku baja
Toko besi beton sii
undangan pernikahan batik
Toko Besi Beton
Pabrik Pipa Besi baja Schedule sch 80
Pabrik besi unp baja
Supplier besi beton interworld steel is
Distributor besi siku baja
Distributor besi siku baja
Agen besi siku
Distributor besi wf
Agen besi Wf Baja
undangan pernikahan
www.sentrabesibaja.com
Distributor Pipa Besi baja
Distributor besi h beam baja
Supplier besi beton gunung garuda

link9