可扩展的listview子位置为每个标头重新启动

时间:2013-09-04 08:38:07

标签: java android eclipse expandablelistview

我有可扩展的列表视图,每次点击一个孩子时,我会根据ChildPosition确定要打开的内容。但问题是ChildPosition重置“headre row”。例如,我有Header 1和Header 2,两个标题都有4个孩子。标题1下的Child1位置为0,标题2下的child1位置也为0.

这会破坏我的代码,因为我总是将ChildPosition作为额外的活动传递给下一个活动,并根据该int打开另一个WebView。这是代码:

传递额外费用:

expListView.setOnChildClickListener(new OnChildClickListener(){

        @Override
        public boolean onChildClick(ExpandableListView arg0, View arg1,
                int arg2, int childPosition, long arg4) {
            //Starting intent
            Intent scheudele = new Intent(MainActivity.this, Scheudele.class);
            scheudele.putExtra("razred", childPosition);
            startActivity(scheudele);
            Log.i("TAG", "Position: " + childPosition);
            return false;
        }

    });

使用该额外内容加载网址:

public void getWebView(){
    razredData = getIntent();
    int position = razredData.getIntExtra("razred", 0);
    String urlToLoad = null;

    switch (position){
    case 0:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/16515/0/0/1";
        break;
    case 1:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/16520/0/0/1";
        break;
    case 2:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/16516/0/0/1";
        break;
    case 3:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/16517/0/0/1";
        break;
    case 4:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/16518/0/0/1";
        break;
    case 5:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18222/0/0/1";
        break;
    case 6:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18223/0/0/1";
        break;
    case 7:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18224/0/0/1";
        break;
    case 8:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18225/0/0/1";
        break;
    case 9:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18215/0/0/1";
        break;
    case 10:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18216/0/0/1";
        break;
    case 11:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18217/0/0/1";
        break;
    case 12:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18219/0/0/1";
        break;
    case 13:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18220/0/0/1";
        break;
    case 14:
        urlToLoad = "https://www.easistent.com/urniki/izpis/263/18221/0/0/1";
        break;
    }

    //Loading WebView URL
    webView.loadUrl(urlToLoad);
    webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
}

所以,正如你已经可以想象的那样;如果我单击Header 1下的子节点,则会显示正确的URL,但是在我开始单击Header 2下的子节点后,它们的位置将重置为0并再次显示“case 0”url。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

onChildClick()中,还有参数int groupPosition,但您将其设为int arg2

然后你可以将groupPosition作为附加内容传递,并通过groupPosition决定加载哪个url。

请参阅OnChildClickListener的文档: http://developer.android.com/reference/android/widget/ExpandableListView.OnChildClickListener.html