androidcrashexpandablelistview

expandable list view crashes after some child click


i have a project that use expandable list view with custom adapter. my list view works currectly while but the problem is after while these two problems starts: 1- wrong child onclick is starts. my clicked child wont work but another 2- after some clicks app is crashesh.

this is my adapter:

@SuppressWarnings("unchecked")

public class NewAdapter extends BaseExpandableListAdapter {

public ArrayList<String> groupItem, tempChild;
public ArrayList<Object> Childtem = new ArrayList<Object>();
public LayoutInflater minflater;
public Activity activity;

public NewAdapter(ArrayList<String> grList, ArrayList<Object> childItem) {
    groupItem = grList;
    this.Childtem = childItem;
}

public void setInflater(LayoutInflater mInflater, Activity act) {
    this.minflater = mInflater;
    activity = act;
}

public Object getChild(int groupPosition, int childPosition) {
    return null;
}

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


 
public View getChildView(int groupPosition, final int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent) {
    tempChild = (ArrayList<String>) Childtem.get(groupPosition);
    TextView text = null;
    if (convertView == null) {
        convertView = minflater.inflate(R.layout.childrow, null);
    }
    text = (TextView) convertView.findViewById(R.id.textView1);
    text.setText(tempChild.get(childPosition));
    //typeface
    text.setTypeface(G.typeFacePrs);
    //************
    convertView.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
    
            Log.i("LOG", "childposition"+tempChild.get(childPosition));
            
            
            //customized toast by Mahdi Tajik
            Toast toast = Toast.makeText(activity, tempChild.get(childPosition),Toast.LENGTH_LONG);
            Log.i("LOG", "tempChild.get(childPosition)"+tempChild.get(childPosition));
            View view = toast.getView();
            view.setBackgroundColor(Color.parseColor("#e60017"));
            toast.setGravity(Gravity.BOTTOM, 0, 78);
            TextView text = (TextView) view.findViewById(android.R.id.message);
            //text.setText("balabalalalalalal");
            //here you can do anything with text
            //toast.setView(text);
            toast.show();
            loadContent(tempChild.get(childPosition));
            
            /*custom toast by: mahdi tajik
             * 
             Toast toast = new Toast(context);
            toast.setDuration(Toast.LENGTH_LONG);

            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
            View view = inflater.inflate(R.layout.custom_layout, null);
            toast.setView(view);
            toast.show();
             * 
             */
            
        }

        private void loadContent(String key) {
            
            Class distination_act = ContentActivity.class;
            Activity myAct = G.currentActivity;
            
            String mDrawableName = "";
            
            if(key=="تغییر در عادات روده ای و مثانه"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_1001);
                mDrawableName = "text_1001";
            }
            if(key=="پشت درد مداوم، تغییر رنگ ادرار و مدفوع"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_1002);
                mDrawableName = "text_1002";
            }
            if(key=="افسردگی"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_1003);
                mDrawableName = "text_1003";
            }
            if(key=="عفونت کلامیدیائی"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_2001);
                mDrawableName = "text_2001";
            }
            if(key=="سوزاک"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_2002);
                mDrawableName = "text_2002";
            }
            if(key=="سیفیلیس"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_2003);
                mDrawableName = "text_2003";
            }
            if(key=="تبخال تناسلی"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_2004);
                mDrawableName = "text_2004";
            }
            if(key=="زگیل تناسلی"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_2005);
                mDrawableName = "text_2005";
            }
            if(key=="ایدز"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_2006);
                mDrawableName = "text_2006";
            }
            if(key=="التهاب پروستات"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_3001);
                mDrawableName = "text_3001";
            }
            if(key=="بزرگی خوش خیم پروستات"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_3002);
                mDrawableName = "text_3002";
            }
            if(key=="سرطان پروستات"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_3003);
                mDrawableName = "text_3003";
            }
            if(key=="افزایش فشار خون"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_4001);
                mDrawableName = "text_4001";
            }
            if(key=="بیماری عروق کرونری قلب"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_4002);
                mDrawableName = "text_4002";
            }
            if(key=="سکته قلبی"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_4003);
                mDrawableName = "text_4003";
            }
            if(key=="دیابت"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_5001);
                mDrawableName = "text_5001";
            }
            if(key=="سرطان بیضه"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_6001);
                mDrawableName = "text_6001";
            }
            if(key=="زندگی سالم"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_7001);
                mDrawableName = "text_7001";
            }
            if(key=="یک رژیم غذائی سالم به چه چیزی شبیه است؟"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_8001);
                mDrawableName = "text_8001";
            }
            if(key=="رژیم غذائی و کاهش وزن"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_8002);
                mDrawableName = "text_8002";
            }
            if(key=="ورزش"){
                G.must_load_content = G.currentActivity.getString(R.string.content_text_9001);
                mDrawableName = "text_9001";
            }
            if(key=="ورزش موثر"){
                //G.must_load_content = G.currentActivity.getString(R.string.content_text_9002);
                distination_act = EfectiveSportActivity.class;
                mDrawableName = "text_9002";
            }
            
            Resources res = G.currentActivity.getResources();
            Log.i("LOG", "pont1 ");
            int resID = res.getIdentifier(mDrawableName , "drawable", G.currentActivity.getPackageName());
            Log.i("LOG", "pont2");
            G.must_load_image_of_content = res.getDrawable(resID );
            Log.i("LOG", "pont3");
            Intent i = new Intent(G.currentActivity,distination_act);
            Log.i("LOG", "pont4");
            
            myAct.startActivity(i);
            
            
        }
    });
    return convertView;
}

public int getChildrenCount(int groupPosition) {
    return ((ArrayList<String>) Childtem.get(groupPosition)).size();
}

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

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

@Override
public void onGroupCollapsed(int groupPosition) {
    super.onGroupCollapsed(groupPosition);
}

@Override
public void onGroupExpanded(int groupPosition) {
    super.onGroupExpanded(groupPosition);
}

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

public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent) {
    if (convertView == null) {
        convertView = minflater.inflate(R.layout.grouprow, null);
    }

    ((CheckedTextView) convertView).setText(groupItem.get(groupPosition));
    ((CheckedTextView) convertView).setChecked(isExpanded);
    
    return convertView;
}



public boolean hasStableIds() {
    return false;
}

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

}

and this is the activity

public class HealthActivity extends ExpandableListActivity implements
OnChildClickListener {

ExpandableListView expandbleLis=null;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
 expandbleLis = getExpandableListView();

G.currentActivity = HealthActivity.this;

expandbleLis.setDividerHeight(3);
expandbleLis.setGroupIndicator(null);
expandbleLis.setClickable(true);

setGroupData();
setChildGroupData();

NewAdapter mNewAdapter = new NewAdapter(groupItem, childItem);
mNewAdapter
        .setInflater((LayoutInflater)             getSystemService(Context.LAYOUT_INFLATER_SERVICE),this);
getExpandableListView().setAdapter(mNewAdapter);
expandbleLis.setOnChildClickListener(this);
}

public void setGroupData() {
groupItem.add("علائم هشدار دهنده");
groupItem.add("بیماری های جنسی");
groupItem.add("سلامت پروستات");
groupItem.add("سیستم قلبی عروقی");
groupItem.add("دیابت");
groupItem.add("سرطانها");
groupItem.add("اقدامات برای بهبود کیفیت زندگی");
groupItem.add("تغذیه");
groupItem.add("ورزش و توانائی جسمی");
}

ArrayList<String> groupItem = new ArrayList<String>();
ArrayList<Object> childItem = new ArrayList<Object>();

public void setChildGroupData() {
/**
 * Add Data For TecthNology
 */
ArrayList<String> child = new ArrayList<String>();
child.add("تغییر در عادات روده ای و مثانه"); //string 1001
child.add("پشت درد مداوم، تغییر رنگ ادرار و مدفوع"); //string 1002
child.add("افسردگی"); //string 1003

childItem.add(child);

/**
 * Add Data For Mobile
 */
child = new ArrayList<String>();
child.add("عفونت کلامیدیائی"); //string 2001
child.add("سوزاک"); //string 2002
child.add("سیفیلیس"); //string 2003
child.add("تبخال تناسلی"); //string 2004
child.add("زگیل تناسلی"); //string 2005
child.add("ایدز"); //string 2006
childItem.add(child);
/**
 * Add Data For Manufacture
 */
child = new ArrayList<String>();
child.add("التهاب پروستات"); //string 3001
child.add("بزرگی خوش خیم پروستات"); //string 3002
child.add("سرطان پروستات"); //string 3003

childItem.add(child);
/**
 * Add Data For Extras
 */
child = new ArrayList<String>();
child.add("افزایش فشار خون"); //string 4001
child.add("بیماری عروق کرونری قلب"); //string 4002
child.add("سکته قلبی"); //string 4003
childItem.add(child);

child = new ArrayList<String>();
child.add("دیابت"); //string 5001
childItem.add(child);

child = new ArrayList<String>();
child.add("سرطان بیضه"); //string 6001
childItem.add(child);


child = new ArrayList<String>();
child.add("زندگی سالم"); //string 7001


childItem.add(child);
child = new ArrayList<String>();
child.add("یک رژیم غذائی سالم به چه چیزی شبیه است؟"); //string 8001
child.add("رژیم غذائی و کاهش وزن"); //string 8002

childItem.add(child);

child = new ArrayList<String>();
child.add("ورزش"); //string 9001
child.add("ورزش موثر"); //string 9002

childItem.add(child);


}

@Override
public boolean onChildClick(ExpandableListView parent, View v,
        int groupPosition, int childPosition, long id) {
    Toast.makeText(HealthActivity.this, "Clicked On Child",
            Toast.LENGTH_SHORT).show();
    //parent.expandGroup(-1);
    //parent.collapseGroup(groupPosition);
    expandbleLis.collapseGroup(groupPosition);
        
return true;
}
}

edited code is:

import java.security.acl.Group;
import java.util.ArrayList;


import android.R.color;
import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseExpandableListAdapter;
import android.widget.CheckedTextView;
import android.widget.TextView;
import android.widget.Toast;



@SuppressWarnings("unchecked")
public class NewAdapter extends BaseExpandableListAdapter {

    public int previousGroup=-1; 
    
    
    
    public ArrayList<String> groupItem, tempChild;
    public ArrayList<Object> Childtem = new ArrayList<Object>();
    public LayoutInflater minflater;
    public Activity activity=null;

    public NewAdapter(ArrayList<String> grList, ArrayList<Object> childItem) {
        groupItem = grList;
        this.Childtem = childItem;
    }

    public void setInflater(LayoutInflater mInflater, Activity act) {
        this.minflater = mInflater;
        activity = act;
    }

    public Object getChild(int groupPosition, int childPosition) {
        return null;
    }

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

    
     
    public View getChildView(int groupPosition, final int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        
        convertView.setTag(groupPosition*100 + childPosition);
        
        final int myGroupPos = groupPosition;
        final DisplayMetrics dm = new DisplayMetrics();
        activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
        
        previousGroup = myGroupPos;
        tempChild = (ArrayList<String>) Childtem.get(groupPosition);
        TextView text = null;
        if (convertView == null) {
            convertView = minflater.inflate(R.layout.childrow, null);
        }
        
    
        /*
        text = (TextView) convertView.findViewById(R.id.textView1);
        text.setText(tempChild.get(childPosition));
        //typeface
        text.setTypeface(G.typeFacePrs);
        */
        //************
        convertView.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
        
                Log.i("LOG", "childposition"+tempChild.get(childPosition));
                
                ReportActivity.mahdiCustomToast(tempChild.get(childPosition), 1);
            
                
                loadContent(tempChild.get(childPosition));
                previousGroup = myGroupPos;
                
                
            }

            private void loadContent(String key) {
                
                
                
                
            }
        });
        return convertView;
    }

    public int getChildrenCount(int groupPosition) {
        return ((ArrayList<String>) Childtem.get(groupPosition)).size();
    }

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

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

    @Override
    public void onGroupCollapsed(int groupPosition) {
        super.onGroupCollapsed(groupPosition);
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);   
        
    }

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

    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = minflater.inflate(R.layout.grouprow, null);
        }
    
        ((CheckedTextView) convertView).setText(groupItem.get(groupPosition));
        ((CheckedTextView) convertView).setChecked(isExpanded);
        
        return convertView;
    }
    

    public boolean hasStableIds() {
        return false;
    }

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

}

log cat is:

12-21 10:37:42.628: D/libEGL(5084): loaded /system/lib/egl/libGLESv2_adreno200.so
12-21 10:37:42.628: I/Adreno200-EGL(5084): <qeglDrvAPI_eglInitialize:265>: EGL 1.4 QUALCOMM build: HAREESHG_Nondeterministic_AU+PATCH[ES]_msm8960_JB_1.9.6_MR2_CL3219408_release_ENGG (CL3219408)
12-21 10:37:42.628: I/Adreno200-EGL(5084): Build Date: 09/28/13 Sat
12-21 10:37:42.628: I/Adreno200-EGL(5084): Local Branch: hhh
12-21 10:37:42.628: I/Adreno200-EGL(5084): Remote Branch: quic/jb_1.9.6_1
12-21 10:37:42.628: I/Adreno200-EGL(5084): Local Patches: 8d50ec23e42ef52b570aa6ff1650afac0b503d78 CL3219408: Fix in the Glreadpixels for negative offsets and larger dimensions.
12-21 10:37:42.628: I/Adreno200-EGL(5084):                  801859126f6ca69482b39a34ca61447e3f7cded8 rb: fix panel settings to clear undrawn/undefined buffers
12-21 10:37:42.628: I/Adreno200-EGL(5084): Reconstruct Branch: LOCAL_PATCH[ES]
12-21 10:37:42.718: D/OpenGLRenderer(5084): Enabling debug mode 0
12-21 10:37:42.728: D/OpenGLRenderer(5084): GL error from OpenGLRenderer: 0x502
12-21 10:37:42.728: E/OpenGLRenderer(5084):   GL_INVALID_OPERATION
12-21 10:37:46.482: D/skia(5084): new locale 
12-21 10:38:01.989: D/skia(5731): new locale 
12-21 10:38:02.069: D/libEGL(5731): loaded /system/lib/egl/libEGL_adreno200.so
12-21 10:38:02.069: D/libEGL(5731): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
12-21 10:38:02.099: D/libEGL(5731): loaded /system/lib/egl/libGLESv2_adreno200.so
12-21 10:38:02.109: I/Adreno200-EGL(5731): <qeglDrvAPI_eglInitialize:265>: EGL 1.4 QUALCOMM build: HAREESHG_Nondeterministic_AU+PATCH[ES]_msm8960_JB_1.9.6_MR2_CL3219408_release_ENGG (CL3219408)
12-21 10:38:02.109: I/Adreno200-EGL(5731): Build Date: 09/28/13 Sat
12-21 10:38:02.109: I/Adreno200-EGL(5731): Local Branch: hhh
12-21 10:38:02.109: I/Adreno200-EGL(5731): Remote Branch: quic/jb_1.9.6_1
12-21 10:38:02.109: I/Adreno200-EGL(5731): Local Patches: 8d50ec23e42ef52b570aa6ff1650afac0b503d78 CL3219408: Fix in the Glreadpixels for negative offsets and larger dimensions.
12-21 10:38:02.109: I/Adreno200-EGL(5731):                  801859126f6ca69482b39a34ca61447e3f7cded8 rb: fix panel settings to clear undrawn/undefined buffers
12-21 10:38:02.109: I/Adreno200-EGL(5731): Reconstruct Branch: LOCAL_PATCH[ES]
12-21 10:38:02.269: D/OpenGLRenderer(5731): Enabling debug mode 0
12-21 10:38:06.554: D/AbsListView(5731): Get MotionRecognitionManager
12-21 10:38:06.754: D/AbsListView(5731): unregisterIRListener() is called 
12-21 10:38:06.934: D/AbsListView(5731): unregisterIRListener() is called 
12-21 10:38:07.024: D/AbsListView(5731): unregisterIRListener() is called 
12-21 10:38:08.145: D/AndroidRuntime(5731): Shutting down VM
12-21 10:38:08.155: W/dalvikvm(5731): threadid=1: thread exiting with uncaught exception (group=0x418dc898)
12-21 10:38:08.175: E/AndroidRuntime(5731): FATAL EXCEPTION: main
12-21 10:38:08.175: E/AndroidRuntime(5731): java.lang.NullPointerException
12-21 10:38:08.175: E/AndroidRuntime(5731):     at com.tebsoft.his.NewAdapter.getChildView(NewAdapter.java:63)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:455)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.AbsListView.obtainView(AbsListView.java:2624)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.ListView.makeAndAddView(ListView.java:1852)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.ListView.fillDown(ListView.java:682)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.ListView.fillSpecific(ListView.java:1345)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.ListView.layoutChildren(ListView.java:1645)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.AbsListView.onLayout(AbsListView.java:2444)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1677)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1531)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1440)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.View.layout(View.java:15221)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewGroup.layout(ViewGroup.java:4793)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2260)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2007)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1249)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6364)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.Choreographer.doCallbacks(Choreographer.java:591)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.Choreographer.doFrame(Choreographer.java:561)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.os.Handler.handleCallback(Handler.java:730)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.os.Handler.dispatchMessage(Handler.java:92)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.os.Looper.loop(Looper.java:137)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at android.app.ActivityThread.main(ActivityThread.java:5455)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at java.lang.reflect.Method.invokeNative(Native Method)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at java.lang.reflect.Method.invoke(Method.java:525)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
12-21 10:38:08.175: E/AndroidRuntime(5731):     at dalvik.system.NativeStart.main(Native Method)

Solution

  • first thing that i can say to you is that you must use tag to each view that make you easy work with your view, and then you don't needed to check the key, like bellow code:

        convertView.setTag(groupPosition*100 + childPosition);
    

    with this code you have one unique tag for each child item, then in onClick method you can get you tag like v.getTag(). this get to you your unique tag and you can get your child position easily.

    second thing that i see in your code and not true is when you want check your String you use ==. you must use .equal() in String check.

    // Edit

    you must put seTag() into getChildView().

    for the getting your child use following code:

    int chiledposClicked = v.getTag() % 100;
    int groupPosClicked = v.getTag() / 100;
    

    then you can get your child with

    Childtem.get(groupPosClicked).get(chiledposClicked);
    

    Result

    public View getChildView(int groupPosition, final int childPosition,
                boolean isLastChild, View convertView, ViewGroup parent) {
    
    
    
            final int myGroupPos = groupPosition;
            final DisplayMetrics dm = new DisplayMetrics();
            activity.getWindowManager().getDefaultDisplay().getMetrics(dm);
    
            previousGroup = myGroupPos;
            tempChild = (ArrayList<String>) Childtem.get(groupPosition);
            TextView text = null;
            if (convertView == null) {
                convertView = minflater.inflate(R.layout.childrow, null);
            }
    
            convertView.setTag(groupPosition*100 + childPosition);
            /*
            text = (TextView) convertView.findViewById(R.id.textView1);
            text.setText(tempChild.get(childPosition));
            //typeface
            text.setTypeface(G.typeFacePrs);
            */
            //************
            convertView.setOnClickListener(new OnClickListener() {
                public void onClick(View v) {
    
    
                    int chiledposClicked = v.getTag() % 100;
                    int groupPosClicked = v.getTag() / 100;
    
                     log.d("Group pos and child pos",""+groupPosClicked +" "+ chiledposClicked);
    
                     Childtem.get(groupPosClicked).get(chiledposClicked);
    
                    log.d("chiled is",Childtem.get(groupPosClicked).get(chiledposClicked));
                    ReportActivity.mahdiCustomToast(Childtem.get(groupPosClicked).get(chiledposClicked)
                                            , 1);
    
    
                    loadContent(Childtem.get(groupPosClicked).get(chiledposClicked));
    
    
                }
    
                private void loadContent(String key) {
    
    
    
    
                }
            });
            return convertView;
        }