Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 骑 公共视图getChildView(int-groupPosition、int-childPosition、boolean-isLastChild、View-convertView、ViewGroup-ViewGroup){ 视图v=转换视图; //至于使用网格视图,只有一个子视图,没有适合重用/回收的视图。 //如果(v==null){ LayoutFlater充气器=(LayoutFlater)this.context.getSystemService(context.LAYOUT\u充气器\u服务); v=充气机。充气(R.layout.history\u list\u child,空); //} TextView itemPropCode=(TextView)v.findViewById(R.id.historyPropertyCode); TextView itemPropName=(TextView)v.findViewById(R.id.historyPropertyName); GridView项目Grid=(GridView)v.findViewById(R.id.historyItemList); //获取此组/标题的子列表。 List history_List_child=getGroup(groupPosition).getItemGrid(); //至于使用网格视图,onChildClickListener无法使用。您可能需要传递组/头对象 //连接到网格视图适配器,并在getView内单击一次。首先尝试使用原始方法正确显示数据。 ItemGridAdapter=新的ItemGridAdapter(上下文、历史\列表\子项); setAdapter(适配器); HistoryDetail详细信息=_listDataHeader.get(groupPosition).getItemList().get(childPosition); setText(detail.getPropertyCode()); itemPropName.setText(detail.getPropertyName()); 返回v; } @凌驾 公共布尔值isChildSelectable(int-groupPosition,int-childPosition){ 返回true; } }_Java_Android_Database_Gridview_Expandablelistview - Fatal编程技术网

Java 骑 公共视图getChildView(int-groupPosition、int-childPosition、boolean-isLastChild、View-convertView、ViewGroup-ViewGroup){ 视图v=转换视图; //至于使用网格视图,只有一个子视图,没有适合重用/回收的视图。 //如果(v==null){ LayoutFlater充气器=(LayoutFlater)this.context.getSystemService(context.LAYOUT\u充气器\u服务); v=充气机。充气(R.layout.history\u list\u child,空); //} TextView itemPropCode=(TextView)v.findViewById(R.id.historyPropertyCode); TextView itemPropName=(TextView)v.findViewById(R.id.historyPropertyName); GridView项目Grid=(GridView)v.findViewById(R.id.historyItemList); //获取此组/标题的子列表。 List history_List_child=getGroup(groupPosition).getItemGrid(); //至于使用网格视图,onChildClickListener无法使用。您可能需要传递组/头对象 //连接到网格视图适配器,并在getView内单击一次。首先尝试使用原始方法正确显示数据。 ItemGridAdapter=新的ItemGridAdapter(上下文、历史\列表\子项); setAdapter(适配器); HistoryDetail详细信息=_listDataHeader.get(groupPosition).getItemList().get(childPosition); setText(detail.getPropertyCode()); itemPropName.setText(detail.getPropertyName()); 返回v; } @凌驾 公共布尔值isChildSelectable(int-groupPosition,int-childPosition){ 返回true; } }

Java 骑 公共视图getChildView(int-groupPosition、int-childPosition、boolean-isLastChild、View-convertView、ViewGroup-ViewGroup){ 视图v=转换视图; //至于使用网格视图,只有一个子视图,没有适合重用/回收的视图。 //如果(v==null){ LayoutFlater充气器=(LayoutFlater)this.context.getSystemService(context.LAYOUT\u充气器\u服务); v=充气机。充气(R.layout.history\u list\u child,空); //} TextView itemPropCode=(TextView)v.findViewById(R.id.historyPropertyCode); TextView itemPropName=(TextView)v.findViewById(R.id.historyPropertyName); GridView项目Grid=(GridView)v.findViewById(R.id.historyItemList); //获取此组/标题的子列表。 List history_List_child=getGroup(groupPosition).getItemGrid(); //至于使用网格视图,onChildClickListener无法使用。您可能需要传递组/头对象 //连接到网格视图适配器,并在getView内单击一次。首先尝试使用原始方法正确显示数据。 ItemGridAdapter=新的ItemGridAdapter(上下文、历史\列表\子项); setAdapter(适配器); HistoryDetail详细信息=_listDataHeader.get(groupPosition).getItemList().get(childPosition); setText(detail.getPropertyCode()); itemPropName.setText(detail.getPropertyName()); 返回v; } @凌驾 公共布尔值isChildSelectable(int-groupPosition,int-childPosition){ 返回true; } },java,android,database,gridview,expandablelistview,Java,Android,Database,Gridview,Expandablelistview,希望有帮助 谢谢你的回复@I_A_Mok!我尝试添加您建议的行,并相应地更改HistoryAdapter,但我不确定如何更改ItemGridAdapter.java以匹配添加的行。我在显示GridItems GridItems=itemList.get(position)的行中遇到不兼容类型错误。您能告诉我在添加这些行之后,如何设置gridview的文本吗?再次感谢!我刚刚注意到,您可以将网格列表放在header类中,因此我稍微更改了代码(用Changed2注释的3行代码),并添加了适配器代码。

希望有帮助

谢谢你的回复@I_A_Mok!我尝试添加您建议的行,并相应地更改HistoryAdapter,但我不确定如何更改ItemGridAdapter.java以匹配添加的行。我在显示
GridItems GridItems=itemList.get(position)的行中遇到不兼容类型错误。您能告诉我在添加这些行之后,如何设置gridview的文本吗?再次感谢!我刚刚注意到,您可以将网格列表放在header类中,因此我稍微更改了代码(用Changed2注释的3行代码),并添加了适配器代码。你也可以看看我的答案:,嘿,我阿莫,再次感谢你帮我做这件事。我已经尝试了您提供的更改,但我似乎无法使这一行正常工作:
List history\u List\u child=getGroup(groupPosition).getItemGrid()。它给了我一个无法解析的方法getItemGrid()错误。我试图修改它,但似乎无法找到如何使用
list
ArrayList
获取组的子列表。我也查看了您提供的链接,但两者似乎都使用HashMap方法,并且与我的代码的结构略有不同,因此我有点迷茫。你能告诉我我遗漏了什么吗?顺便说一下,不用担心gridview的
onChildClickListener
。实际上,我想在我的应用程序中禁用它,因为网格的全部目的只是显示值。这就是我在ItemGridAdapter中添加最后2个布尔代码的原因。再次感谢!请注意,在我的适配器中,getGroup返回HistoryHeader而不是object。我忘了把它标记为已更改。
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.history_tab_layout, container, false);

    openHelper = new DatabaseHelper(getActivity());
    myDb = openHelper.getReadableDatabase();
    TextView _number = (TextView) rootView.findViewById(R.id.lblNumber);
    TextView _date = (TextView) rootView.findViewById(R.id.lblHistoryDate);
    TextView _transtype = (TextView) rootView.findViewById(R.id.lblHistoryTransType);
    TextView _amount = (TextView) rootView.findViewById(R.id.lblHistoryAmount);

    Cursor mCursor = null;
    Cursor dataCursor = null;
    Cursor itemCursor = null;
    String Query = "SELECT * FROM Requests";
    mCursor = myDb.rawQuery(Query, null);
    transHistory = new ArrayList<HistoryHeader>();
    gridHistory = new ArrayList<GridItems>();
    int count = 1;
    if(mCursor.getCount()!=0) {
        while (mCursor.moveToNext()) {
            String reqDate = mCursor.getString(mCursor.getColumnIndex("RequestDate"));
            String reqTransType = mCursor.getString(mCursor.getColumnIndex("TransType"));
            String reqTotalAmt = mCursor.getString(mCursor.getColumnIndex("AmtTotal"));
            String reqPCode = mCursor.getString(mCursor.getColumnIndex("Property"));
            String BaseId = mCursor.getString(0);
            HistoryHeader history = new HistoryHeader(count, reqDate, reqTransType, reqTotalAmt);

            String Query2 = "SELECT * FROM Projects WHERE PrjCode = '"+ mCursor.getString(3) +"'";
            dataCursor = myDb.rawQuery(Query2, null);
            if (dataCursor.getCount()!=0){
                while (dataCursor.moveToNext()){
                    String reqPName = dataCursor.getString(dataCursor.getColumnIndex("PrjName"));
                    history.setItemList(createItems(reqPCode, reqPName, 1));
                }
            }

            String Query3 = "SELECT * FROM ReqLine WHERE Base_Id = "+ BaseId;
            itemCursor = myDb.rawQuery(Query3, null);
            if (itemCursor.getCount()!=0) {
                while (itemCursor.moveToNext()) {
                    String reqPurpose = itemCursor.getString(itemCursor.getColumnIndex("Purpose"));
                    String reqAmount = itemCursor.getString(itemCursor.getColumnIndex("AmtLine"));
                    Integer reqNum = itemCursor.getInt(itemCursor.getColumnIndex("Linenum"));
                    GridItems test = new GridItems(reqNum, reqPurpose, reqAmount);
                    gridHistory.add(test);
                }
            }

            transHistory.add(history);
            count++;
        }
    }

    final ExpandableListView _Content = (ExpandableListView) rootView.findViewById(R.id.historyList);
    _Content.setIndicatorBounds(5,5);
    HistoryAdapter exAdpt = new HistoryAdapter(getActivity(), transHistory, gridHistory);
    _Content.setIndicatorBounds(0,20);
    _Content.setAdapter(exAdpt);

    return rootView;
}

private List<HistoryDetail> createItems(String _strPropertyCode, String _strPropertyName, int num) {
    List<HistoryDetail> result = new ArrayList<HistoryDetail>();
    for (int i=0; i < num; i++) {
        HistoryDetail item = new HistoryDetail(i, _strPropertyCode, _strPropertyName);
        result.add(item);
    }
    return result;
}
public class HistoryAdapter extends BaseExpandableListAdapter {
private Context context;
private List<HistoryHeader> _listDataHeader;
private ArrayList<GridItems> _listGridItems;

public HistoryAdapter(Context context, List<HistoryHeader> _listDataHeader, ArrayList<GridItems> _listGridItems) {
    this.context = context;
    this._listDataHeader = _listDataHeader;
    this._listGridItems = _listGridItems;
}

@Override
public int getGroupCount() {
    return _listDataHeader.size();
}

@Override
public int getChildrenCount(int groupPosition) {
    /*Integer size = _listDataHeader.get(groupPosition).getItemList().size();
    return size;*/
    return 1;
}

@Override
public Object getGroup(int groupPosition) {
    return _listDataHeader.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    return _listDataHeader.get(groupPosition).getItemList().get(childPosition);
}

@Override
public long getGroupId(int groupPosition) {
    return _listDataHeader.get(groupPosition).hashCode();
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    return _listDataHeader.get(groupPosition).getItemList().get(childPosition).hashCode();
}

@Override
public boolean hasStableIds() {
    return true;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup viewGroup) {
    View v = convertView;
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.history_list_group, null);
    }
    TextView groupNum = (TextView) v.findViewById(R.id.historyNumber);
    TextView groupDate = (TextView) v.findViewById(R.id.historyDate);
    TextView groupTransType = (TextView) v.findViewById(R.id.historyTransType);
    TextView groupAmount = (TextView) v.findViewById(R.id.historyTotalAmt);

    HistoryHeader header = _listDataHeader.get(groupPosition);

    groupNum.setText(String.valueOf(header.getId()));
    groupDate.setText(header.getDate());
    groupTransType.setText(header.getTransType());
    groupAmount.setText(header.getTotalAmt());

    return v;
}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup viewGroup) {
    View v = convertView;
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.history_list_child, null);
    }
    TextView itemPropCode = (TextView) v.findViewById(R.id.historyPropertyCode);
    TextView itemPropName = (TextView) v.findViewById(R.id.historyPropertyName);
    GridView itemGrid = (GridView) v.findViewById(R.id.historyItemList);
    ItemGridAdapter adapter = new ItemGridAdapter(context,_listGridItems);
    itemGrid.setAdapter(adapter);

    HistoryDetail detail = _listDataHeader.get(groupPosition).getItemList().get(childPosition);

    itemPropCode.setText(detail.getPropertyCode());
    itemPropName.setText(detail.getPropertyName());

    return v;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}
public class ItemGridAdapter extends BaseAdapter {
Context context;
ArrayList<GridItems> itemList;

public ItemGridAdapter(Context context, ArrayList<GridItems> itemList) {
    this.context = context;
    this.itemList = itemList;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return itemList.size();
}

@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = inflater.inflate(R.layout.history_grid_layout, null);
    }

    TextView _rowPurpose = (TextView) convertView.findViewById(R.id.rowPurpose);
    TextView _rowAmount = (TextView) convertView.findViewById(R.id.rowAmount);

    GridItems gridItems = itemList.get(position);
    _rowPurpose.setText(gridItems.getPurpose());
    _rowAmount.setText(gridItems.getAmount());

    return convertView;
}

@Override
public boolean areAllItemsEnabled() {
    return false;
}

@Override
public boolean isEnabled(int position) {
    // Return true for clickable, false for not
    return false;
}
public class HistoryHeader implements Serializable {
private long id;
private String _strDate;
private String _strTransType;
private String _strTotalAmt;

private List<HistoryDetail> itemDetails = new ArrayList<HistoryDetail>();
private List<GridItems> itemGrid = new ArrayList<>();

public HistoryHeader(long id, String _strDate, String _strTransType, String _strTotalAmt) {
    this.id = id;
    this._strDate = _strDate;
    this._strTransType = _strTransType;
    this._strTotalAmt = _strTotalAmt;
}

public long getId() {
    return id;
}

public void setId(long id) {
    this.id = id;
}

public String getDate() {
    return _strDate;
}

public void setDate(String _strDate) {
    this._strDate = _strDate;
}

public String getTransType() {
    return _strTransType;
}

public void setTransType(String _strTransType) {
    this._strTransType = _strTransType;
}

public String getTotalAmt() {
    return _strTotalAmt;
}

public void setTotalAmt(String _strTotalAmt) {
    this._strTotalAmt = _strTotalAmt;
}

public List<HistoryDetail> getItemList() {
    return itemDetails;
}

public void setItemList(List<HistoryDetail> itemDetails) {
    this.itemDetails = itemDetails;
}

public List<GridItems> getItemGrid(){ return itemGrid; }

public void setItemGrid(List<GridItems> itemGrid) { this.itemGrid = itemGrid; }
public class GridItems {
private long id;
private String _strPurpose, _strAmount;

public GridItems(long id, String _strPurpose, String _strAmount) {
    this.id = id;
    this._strPurpose = _strPurpose;
    this._strAmount = _strAmount;
}

public long getId() {
    return id;
}
public void setId(long id) {
    this.id = id;
}
public String getPurpose() {
    return _strPurpose;
}
public void setPurpose(String _strPurpose) {
    this._strPurpose = _strPurpose;
}
public String getAmount() {
    return _strAmount;
}
public void setAmount(String _strAmount) {
    this._strAmount = _strAmount;
}
Cursor mCursor = null;
Cursor dataCursor = null;
Cursor itemCursor = null;
String Query = "SELECT * FROM Requests";
mCursor = myDb.rawQuery(Query, null);
transHistory = new ArrayList<HistoryHeader>();
//allGridHistory = new ArrayList<ArrayList<GridItems>>(); // Changed2
//gridHistory = new ArrayList<GridItems>();
int count = 1;
if(mCursor.getCount()!=0) {
    while (mCursor.moveToNext()) {
        String reqDate = mCursor.getString(mCursor.getColumnIndex("RequestDate"));
        String reqTransType = mCursor.getString(mCursor.getColumnIndex("TransType"));
        String reqTotalAmt = mCursor.getString(mCursor.getColumnIndex("AmtTotal"));
        String reqPCode = mCursor.getString(mCursor.getColumnIndex("Property"));
        String BaseId = mCursor.getString(0);
        HistoryHeader history = new HistoryHeader(count, reqDate, reqTransType, reqTotalAmt);

        String Query2 = "SELECT * FROM Projects WHERE PrjCode = '"+ mCursor.getString(3) +"'";
        dataCursor = myDb.rawQuery(Query2, null);
        if (dataCursor.getCount()!=0){
            while (dataCursor.moveToNext()){
                String reqPName = dataCursor.getString(dataCursor.getColumnIndex("PrjName"));
                history.setItemList(createItems(reqPCode, reqPName, 1));
            }
        }

        String Query3 = "SELECT * FROM ReqLine WHERE Base_Id = "+ BaseId;
        itemCursor = myDb.rawQuery(Query3, null);
        if (itemCursor.getCount()!=0) {
            gridHistory = new ArrayList<GridItems>(); // Added
            while (itemCursor.moveToNext()) {
                String reqPurpose = itemCursor.getString(itemCursor.getColumnIndex("Purpose"));
                String reqAmount = itemCursor.getString(itemCursor.getColumnIndex("AmtLine"));
                Integer reqNum = itemCursor.getInt(itemCursor.getColumnIndex("Linenum"));
                GridItems test = new GridItems(reqNum, reqPurpose, reqAmount);
                gridHistory.add(test);
            }
            history.setItemGrid(gridHistory); // Changed2
        }

        transHistory.add(history);
        count++;
    }
}

final ExpandableListView _Content = (ExpandableListView) rootView.findViewById(R.id.historyList);
_Content.setIndicatorBounds(5,5);
HistoryAdapter exAdpt = new HistoryAdapter(getActivity(), transHistory); // Changed2
public class HistoryAdapter extends BaseExpandableListAdapter {
private Context context;
private List<HistoryHeader> _listDataHeader;
//private ArrayList<GridItems> _listGridItems;

public HistoryAdapter(Context context, List<HistoryHeader> _listDataHeader) {
    this.context = context;
    this._listDataHeader = _listDataHeader;
    //this._listGridItems = _listGridItems;
}

@Override
public int getGroupCount() {
    return _listDataHeader.size();
}

@Override
public int getChildrenCount(int groupPosition) {
/*Integer size = _listDataHeader.get(groupPosition).getItemList().size();
return size;*/
    return 1;
}

@Override
public HistoryHeader getGroup(int groupPosition) {
    return _listDataHeader.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    return _listDataHeader.get(groupPosition).getItemList().get(childPosition);
}

@Override
public long getGroupId(int groupPosition) {
    return _listDataHeader.get(groupPosition).hashCode();
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    return _listDataHeader.get(groupPosition).getItemList().get(childPosition).hashCode();
}

@Override
public boolean hasStableIds() {
    return true;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup viewGroup) {
    View v = convertView;
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.history_list_group, null);
    }
    TextView groupNum = (TextView) v.findViewById(R.id.historyNumber);
    TextView groupDate = (TextView) v.findViewById(R.id.historyDate);
    TextView groupTransType = (TextView) v.findViewById(R.id.historyTransType);
    TextView groupAmount = (TextView) v.findViewById(R.id.historyTotalAmt);

    HistoryHeader header = _listDataHeader.get(groupPosition);

    groupNum.setText(String.valueOf(header.getId()));
    groupDate.setText(header.getDate());
    groupTransType.setText(header.getTransType());
    groupAmount.setText(header.getTotalAmt());

    return v;
}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup viewGroup) {
    View v = convertView;

    // As for using grid view, there is only one child, no suitable view for reuse/recycle.
    //if (v == null) {
        LayoutInflater inflater = (LayoutInflater) this.context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(R.layout.history_list_child, null);
    //}

    TextView itemPropCode = (TextView) v.findViewById(R.id.historyPropertyCode);
    TextView itemPropName = (TextView) v.findViewById(R.id.historyPropertyName);
    GridView itemGrid = (GridView) v.findViewById(R.id.historyItemList);

    // Get the child list of this group/header.
    List<GridItems> history_list_child = getGroup(groupPosition).getItemGrid();

    // As for using grid view, onChildClickListener cannot be used. You may need to pass the group/header object
    // to grid view adapter and do onClick inside getView. First try your original way to display data correctly.
    ItemGridAdapter adapter = new ItemGridAdapter(context, history_list_child);
    itemGrid.setAdapter(adapter);

    HistoryDetail detail = _listDataHeader.get(groupPosition).getItemList().get(childPosition);
    itemPropCode.setText(detail.getPropertyCode());
    itemPropName.setText(detail.getPropertyName());

    return v;
}

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