2016-01-06 1 views
-1

salut je crée une application qui enregistre mes ventes Facture en sqlite triste montre encore une fois vous pouvez voir des exemples de données dans l'image.ExpandableList crash quand je sélectionne un groupe

enter image description here

enter image description here

maintenant je veux ajouter des données à un adaptateur de liste élargie chaque ligne de HFO est un groupe à mon avis la liste. et chaque MPO qui Hid = id est un enfant pour HFO. je ajoute des données de groupe, mais quand je veux ouvrir un groupe mon application s'est écrasé

s'il vous plaît aider mon réservoir vous.

dfo_listitem.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    android:padding="6dip" > 

    <CheckBox 
     android:id="@+id/checkBoxchilditem" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentRight="true" 
     android:layout_alignTop="@+id/tvchilditem" 
     android:focusable="false" 
     android:focusableInTouchMode="false" /> 

    <TextView 
     android:id="@+id/tvDfo_Rid_child" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="14dp" 
     android:layout_toLeftOf="@+id/checkBoxchilditem" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/tvDfo_Qty_child" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_alignBaseline="@+id/tvDfo_Rid_child" 
     android:layout_alignBottom="@+id/tvDfo_Rid_child" 
     android:layout_toLeftOf="@+id/tvDfo_Rid_child" 
     android:layout_marginRight="5dp" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/tvDfo_Kprice_child" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="14dp" 
     android:layout_toLeftOf="@+id/tvDfo_Qty_child" 
     android:text="TextView" /> 

    <TextView 
     android:id="@+id/tvDfo_Sumprice_child" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_marginRight="14dp" 
     android:text="TextView" /> 

</RelativeLayout> 

hfo_listiem.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:background="#cb9216" > 

    <ImageView 
     android:id="@+id/ivgroup" 
     android:layout_width="40dp" 
     android:layout_height="40dp" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:src="@drawable/abc_btn_check_to_on_mtrl_000" /> 

    <TextView 
     android:id="@+id/tvHfo_Gcode_group" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_margin="5dp" 
     android:layout_toLeftOf="@+id/ivgroup" 
     android:text="TextView" 
     android:textColor="#000000" /> 

    <TextView 
     android:id="@+id/tvHfo_Ttem_group" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_margin="5dp" 
     android:layout_toLeftOf="@+id/tvHfo_Gcode_group" 
     android:text="TextView" 
     android:textColor="#000000" /> 

    <TextView 
     android:id="@+id/tvHfo_SumKprice_group" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_margin="5dp" 
     android:layout_toLeftOf="@+id/tvHfo_Ttem_group" 
     android:text="TextView" 
     android:textColor="#000000" /> 

    <TextView 
     android:id="@+id/tvHfo_tv4_group" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_margin="5dp" 
     android:layout_toLeftOf="@+id/tvHfo_SumKprice_group" 
     android:text="" 
     android:textColor="#000000" /> 

</RelativeLayout> 

fact.xml

<?xml version="1.0" encoding="UTF-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ExpandableListView 
     android:id="@+id/android:list" 
     android:layout_width="fill_parent" 
     android:layout_height="36dp" 
     android:layout_above="@+id/button1" 
     android:layout_alignParentTop="true" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="true" 
     android:text="show data" /> 

    <TextView 
     android:id="@+id/android:empty" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerVertical="true" 
     android:layout_above="@+id/button1" 
     android:text="@string/app_name" /> 

</RelativeLayout> 

DFoStruct.java

 int DFo_HID; 
     int Dfo_RID; 
     String Dfo_KCode; 
     Double Dfo_KQty1; 
     Double Dfo_KQty2; 
     Double Dfo_RUnit1_2; 
     String Dfo_KPrice; 
     String Dfo_KTakh; 
     String Dfo_KTax; 
     String Dfo_SumPrice; 
     String Dfo_KDesc; 
     Boolean State; 

HFoStruct.java

int HFoID; 
int HFoNu; 
String FoKind; 
String HFo_GCode; 
int HFoItem; 
String HFoDesc; 
String HFoTarikh; 
String HFoUn_Takh; 
String HFoK_Takh; 
String HFoTot_Takh; 
String HFoTot_Tax; 
String HFoSum_KPrice; 
String HFoTot_Price; 
String IsSend; 
String SendDate; 
Boolean state; 

mon activité de liste:

public class Listsefaresh_Activity extends ExpandableListActivity { 
     private static final String LOG_TAG = "ElistCBox2"; 
     private ExpandableListAdapter expListAdapter; 

     Button b; 
     ArrayList<String> groupNames; 
     ArrayList<ArrayList<Color>> colors; 
     ArrayList<Color> color; 

     ArrayList<ArrayList<HFoStruct>> hFoStructs; 
     ArrayList<HFoStruct> hFoStruct; 
    // List<GuyStruct> hfolist; 
     List<HFoStruct> hfolist; 

     ArrayList<ArrayList<DFoStruct>> dFoStructs; 
     ArrayList<DFoStruct> dFoStruct; 
     List<DFoStruct> dfolist; 

     /** Called when the activity is first created. */ 
     @Override 
     public void onCreate(Bundle icicle) { 
      super.onCreate(icicle); 
      setContentView(R.layout.factor_list); 

      try { 
       hFoStructs = new ArrayList<ArrayList<HFoStruct>>(); 
       hFoStruct = new ArrayList<HFoStruct>(); 
       dFoStructs = new ArrayList<ArrayList<DFoStruct>>(); 
       dFoStruct = new ArrayList<DFoStruct>(); 

       G.HFoList.addAll(G.dbHelper.getAllHfo()); 
       hfolist = G.HFoList; 

       G.DFoList.addAll(G.dbHelper.getAllDfo()); 
       dfolist = G.DFoList; 

       for (int i = 0; i < hfolist.size(); i++) { 
        hFoStruct.add(hfolist.get(i)); 
        Toast.makeText(Listsefaresh_Activity.this, String.valueOf(hFoStruct.get(i).getHFo_GCode()), Toast.LENGTH_LONG).show(); 
        for (int j = 0; j < dfolist.size(); j++) { 
         if (dfolist.get(j).getDFo_HID() == hfolist.get(i).getHFoID()) { 
          dFoStruct.add(dfolist.get(j)); 
          Toast.makeText(Listsefaresh_Activity.this, String.valueOf(dFoStruct.get(j).getDfo_KPrice()), Toast.LENGTH_LONG).show(); 
         } 
        } 
       } 
       hFoStructs.add(hFoStruct); 
       dFoStructs.add(dFoStruct); 
    //  Toast.makeText(Listsefaresh_Activity.this, String.valueOf(dfolist.size()), Toast.LENGTH_LONG).show(); 

       b = (Button) findViewById(R.id.button1); 

       b.setOnClickListener(new OnClickListener() { 

        @Override 
        public void onClick(View v) { 
         for (int i = 0; i < groupNames.size(); i++) { 
          for (int j = 0; j < colors.get(i).size(); j++) { 
           if (colors.get(i).get(j).state == true) { 
            Toast.makeText(
              Listsefaresh_Activity.this, 
              String.valueOf(groupNames.get(i)) + " " 
                + String.valueOf(j + 1), 
              Toast.LENGTH_LONG).show(); 
           } 
          } 
         } 
        } 
       }); 

    // setdata(); 


       expListAdapter = new Hfo_Dfo_Adabter(this, hfolist, dfolist, hFoStructs, dFoStructs); 
       setListAdapter(expListAdapter); 
      } catch (Exception e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
     } 

     public void onContentChanged() { 
      super.onContentChanged(); 
      Log.d(LOG_TAG, "onContentChanged"); 
     } 

     public boolean onChildClick(ExpandableListView parent, View v, 
       int groupPosition, int childPosition, long id) { 

    } 
} 

Hfo_Dfo_Adabter.java

package my_adabters; 

import ir.nanohesab.R; 

import java.util.ArrayList; 
import java.util.List; 

import Struct.DFoStruct; 
import Struct.HFoStruct; 
import android.content.Context; 
import android.view.LayoutInflater; 
import android.view.View; 
import android.view.ViewGroup; 
import android.widget.BaseExpandableListAdapter; 
import android.widget.CheckBox; 
import android.widget.TextView; 

@SuppressWarnings("unused") 
public class Hfo_Dfo_Adabter extends BaseExpandableListAdapter { 

    private Context context; 
    private List<HFoStruct> hfolist = null; 
    private List<DFoStruct> dfolist = null; 
    private ArrayList<ArrayList<HFoStruct>> hFoStructs = null; 
    private ArrayList<ArrayList<DFoStruct>> dFoStructs = null; 

    /* 
    * private List<HFoStruct> HFolist = null; private List<DFoStruct> DFolist = 
    * null; 
    */ 
    private LayoutInflater inflater; 

    public Hfo_Dfo_Adabter(Context context, List<HFoStruct> hfolist, 
      List<DFoStruct> dfolist, 
      ArrayList<ArrayList<HFoStruct>> hFoStructs, 
      ArrayList<ArrayList<DFoStruct>> dFoStructs) { 
     this.context = context; 
     this.hfolist = hfolist; 
     this.dfolist = dfolist; 
     this.hFoStructs = hFoStructs; 
     this.dFoStructs = dFoStructs; 
     inflater = LayoutInflater.from(context); 
    } 

    public Object getChild(int groupPosition, int childPosition) { 
     try { 
      return dFoStructs.get(groupPosition).get(childPosition); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     return null; 
    } 

    public long getChildId(int groupPosition, int childPosition) { 
     try { 
      return (long) (groupPosition * 1024 + childPosition); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     return (Long) null; 
    } 

    public View getChildView(int groupPosition, int childPosition, 
      boolean isLastChild, View convertView, ViewGroup parent) { 
      View v = null; 

      try { 

      if (convertView != null) 
       v = convertView; 
      else 
       v = inflater.inflate(R.layout.dfo_listitem, parent, false); 
      DFoStruct d = (DFoStruct) getChild(groupPosition, childPosition); 

      TextView tvDfo_Rid_child = (TextView) v 
        .findViewById(R.id.tvDfo_Rid_child); 
      TextView tvDfo_Qty_child = (TextView) v 
        .findViewById(R.id.tvDfo_Qty_child); 
      TextView tvDfo_Kprice_child = (TextView) v 
        .findViewById(R.id.tvDfo_Kprice_child); 
      TextView tvDfo_Sumprice_child = (TextView) v 
        .findViewById(R.id.tvDfo_Sumprice_child); 

      if (tvDfo_Rid_child != null) 
       tvDfo_Rid_child.setText(String.valueOf(d.getDfo_RID())); 
      if (tvDfo_Qty_child != null) 
       tvDfo_Qty_child.setText(String.valueOf(d.getDfo_KQty1())); 

      if (tvDfo_Kprice_child != null) 
       tvDfo_Kprice_child.setText(String.valueOf(d.getDfo_KPrice())); 
      if (tvDfo_Sumprice_child != null) 
       tvDfo_Sumprice_child.setText(String.valueOf(d.getDfo_SumPrice())); 

      CheckBox cb = (CheckBox) v.findViewById(R.id.checkBoxchilditem); 

      cb.setChecked(d.getState()); 
     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     }   
      return v; 

    } 

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

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

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

    public long getGroupId(int groupPosition) { 
     return (long) (groupPosition * 1024); // To be consistent with 
               // getChildId 
    } 

    public View getGroupView(int groupPosition, boolean isExpanded, 
      View convertView, ViewGroup parent) { 
     View v = null; 
     try { 

      if (convertView != null) 
       v = convertView; 
      else 
       v = inflater.inflate(R.layout.hfo_listitem, parent, false); 

      HFoStruct h = hfolist.get(groupPosition); 

      TextView tvHfo_Gcode_group = (TextView) v 
        .findViewById(R.id.tvHfo_Gcode_group); 
      TextView tvHfo_Ttem_group = (TextView) v 
        .findViewById(R.id.tvHfo_Ttem_group); 
      TextView tvHfo_SumKprice_group = (TextView) v 
        .findViewById(R.id.tvHfo_SumKprice_group); 
      TextView tvHfo_tv4_group = (TextView) v 
        .findViewById(R.id.tvHfo_tv4_group); 

      if (tvHfo_Gcode_group != null) 
       tvHfo_Gcode_group.setText(String.valueOf(h.getHFo_GCode())); 

      if (tvHfo_Ttem_group != null) 
       tvHfo_Ttem_group.setText(String.valueOf(h.getHFoItem())); 

      if (tvHfo_SumKprice_group != null) 
       tvHfo_SumKprice_group.setText(String.valueOf(h.getHFoSum_KPrice())); 

      if (tvHfo_tv4_group != null) 
       tvHfo_tv4_group.setText(""); 

     } catch (Exception e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     return v; 

    } 

    public boolean hasStableIds() { 
     return true; 
    } 

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

    public void onGroupCollapsed(int groupPosition) { 
    } 

    public void onGroupExpanded(int groupPosition) { 
    } 

} 


01-06 20:50:03.776: E/AndroidRuntime(1337): FATAL EXCEPTION: main 
    01-06 20:50:03.776: E/AndroidRuntime(1337): Process: ir.nanohesab, PID: 1337 
    01-06 20:50:03.776: E/AndroidRuntime(1337): java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at java.util.ArrayList.get(ArrayList.java:308) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at my_adabters.Hfo_Dfo_Adabter.getChildrenCount(Hfo_Dfo_Adabter.java:102) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.widget.ExpandableListConnector.refreshExpGroupMetadataList(ExpandableListConnector.java:563) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.widget.ExpandableListConnector.expandGroup(ExpandableListConnector.java:688) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.widget.ExpandableListView.handleItemClick(ExpandableListView.java:691) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.widget.ExpandableListView.performItemClick(ExpandableListView.java:651) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.widget.AbsListView$PerformClick.run(AbsListView.java:2904) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.widget.AbsListView$3.run(AbsListView.java:3638) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.os.Handler.handleCallback(Handler.java:733) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.os.Handler.dispatchMessage(Handler.java:95) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.os.Looper.loop(Looper.java:136) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at android.app.ActivityThread.main(ActivityThread.java:5045) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at java.lang.reflect.Method.invokeNative(Native Method) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at java.lang.reflect.Method.invoke(Method.java:515) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 
    01-06 20:50:03.776: E/AndroidRuntime(1337):  at dalvik.system.NativeStart.main(Native Method) 
    01-06 20:50:05.324: E/InputDispatcher(466): channel '4aa23a4c ir.nanohesab/ir.nanohesab.MainActivity (server)' ~ Channel is unrecoverably broken and will be disposed! 
    01-06 20:50:05.324: E/InputDispatcher(466): channel '4aa38234 ir.nanohesab/new_job.Listsefaresh_Activity (server)' ~ Channel is unrecoverably broken and will be disposed! 
    01-06 20:50:05.324: E/InputDispatcher(466): channel '4aa38dec Toast (server)' ~ Channel is unrecoverably broken and will be disposed! 

je veux les données montrent à la liste dépensé et quand je clique sur le bouton i obtenir tout élément vérifié .

+1

s'il vous plaît montrer votre logcat –

+0

@StefanBeike j'envoyer –

+0

S'il vous plaît, modifier votre question, copiez le logcat, puis postez et formatez le texte .. – Bonatti

Répondre

0

le problème est cette méthode:

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

dFoStructs a exactement un élément. Si vous essayez d'obtenir la valeur avec l'index 1, il doit conduire à ArrayIndexOutOfBoundsException car le Array commence à la position 0.

si le comptage des groupPosition commence à la position 1, vous devez veiller à ce que vous réduisez l'indice comme celui-ci:

public int getChildrenCount(int groupPosition) { 
      return dFoStructs.get(groupPosition-1).size(); 
}