mercredi 6 janvier 2016

ExpandableList crash when i select a group

hi I create an app that save my sales Invoice in sqlite sad show it again you can see example data in picture.

enter image description here

now i want add data to a expanded list adapter each row in HFO is a group in my list view. and each DFO that Hid = id is child for HFO. i add group data but when i want open a group my app crashed

please help my tank you.

dfo_listitem.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://ift.tt/nIICcg"
    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://ift.tt/nIICcg"
    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://ift.tt/nIICcg"
    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;

my list activity:

    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) {
    }

}

i want show data to expended list and when i click button i get all checked item.

Aucun commentaire:

Enregistrer un commentaire