组位置始终返回0

时间:2015-11-06 00:54:27

标签: java android expandablelistview expandablelistadapter

至少5个小时我一直在修补这个问题,我无法绕过它。我有可扩展的listview和groupposition总是返回为0.因此。从中获取数据的HashMap始终以一个值开头。我在" getChildView"中找到了孩子的位置和注意力。但它始终以0

开头
@Override
    public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
        if(convertView == null){

            CategoryItem x = (CategoryItem)getChild(groupPosition, childPosition);
            Log.d("EGILS",Integer.toString(groupPosition)+" "+Integer.toString(childPosition));
            LayoutInflater layoutInflater = (LayoutInflater)this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = layoutInflater.inflate(R.layout.child_row, null);

            TextView name = (TextView)convertView.findViewById(R.id.child_Virsraksts);
            TextView price = (TextView)convertView.findViewById(R.id.child_Cena);
            name.setText(x.getItem_name());
            price.setText("€"+Double.toString(GV.round(x.getPrice_notax(),2)));

        }
        //return secondlvl;
       return convertView;

    }

这是我在getChild

之后让我的childView出来的功能
@Override
    public Object getChild(int groupPosition, int childPosition) {
    Log.d("GINTS2", Integer.toString(childPosition) + " " + this.categoryItems.get(this.subcategories.get(groupPosition).getId()).get(childPosition).getItem_name());

        return (Object)this.categoryItems.get(this.subcategories.get(groupPosition).getId()).get(childPosition);
    }

有趣的是,当我在get childview中注销groupposition时,我总是得到0

//1st GROUP PRESSED
11-06 02:50:41.551  19665-19665/com.martinssinka.projektaizmaksas D/EGILS﹕ 0 0

 11-06 02:50:41.561  19665-19665/com.martinssinka.projektaizmaksas D/EGILS﹕ 0 1

11-06 02:50:41.566  19665-19665/com.martinssinka.projektaizmaksas D/EGILS﹕ 0 2

 11-06 02:50:41.571  19665-19665/com.martinssinka.projektaizmaksas D/EGILS﹕ 0 3
//2nd GROUP PRESSED
11-06 02:50:47.052  19665-19665/com.martinssinka.projektaizmaksas D/EGILS﹕ 0 0
//3rd GROUP PRESSED
 11-06 02:50:50.533  19665-19665/com.martinssinka.projektaizmaksas D/EGILS﹕ 0 0

注销GetGroupView(组位置)

11-06 12:07:17.609  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 0 -
11-06 12:07:17.624  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 1 -
11-06 12:07:17.624  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 2 -
11-06 12:07:17.676  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 0 -
11-06 12:07:17.676  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 1 -
11-06 12:07:17.676  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 2 -
11-06 12:07:17.677  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 0 -
11-06 12:07:17.677  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 1 -
11-06 12:07:17.683  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 2 -
11-06 12:07:17.689  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 0 -
11-06 12:07:17.691  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 1 -
11-06 12:07:17.691  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 2 -
11-06 12:07:17.725  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 0 -
11-06 12:07:17.726  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 1 -
11-06 12:07:17.726  30767-30767/com.martinssinka.projektaizmaksas D/GROUPPo﹕ 2 -

1 个答案:

答案 0 :(得分:1)

所以我所做的是创建新项目并将所有类和布局复制到新项目中。并且工作就像一个魅力。

不知道发生了什么,我认为这可能是一个小故障。