2015-01-21 54 views
0

我跟着一个教程,并有一个可扩展的ListView,并希望链接到一个新的活动的孩子 - 我将如何去做到这一点?我是新来的Android所以任何帮助,将不胜感激:)ListView的孩子到新的意图

createGroupList(); 

    createCollection(); 

    expListView = (ExpandableListView) findViewById(R.id.search_list); 
    final ExpandableListAdapter expListAdapter = new ExpandableListAdapter(
      this, groupList, advSearchOption); 
    expListView.setAdapter(expListAdapter); 

    expListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { 

     public boolean onChildClick(ExpandableListView parent, View v, 
            int groupPosition, int childPosition, long id) { 
      final String selected = (String) expListAdapter.getChild(
        groupPosition, childPosition); 
      Toast.makeText(getBaseContext(), selected, Toast.LENGTH_LONG) 
        .show(); 

      return true; 
     } 
    }); 
private void createGroupList() { 
    groupList = new ArrayList<String>(); 
    groupList.add("Advanced Search"); 
} 
private void createCollection() { 
    // preparing laptops collection(child) 
    String[] searches = { "Height", "Weight", 
      "Hair Colour" }; 
    advSearchOption = new LinkedHashMap<String, List<String>>(); 

    for (String advSearch : groupList) { 
     if (advSearch.equals("Advanced Search")) { 
      loadChild(searches); 
     } 

     advSearchOption.put(advSearch, childList); 
    } 
} 
private void loadChild(String[] searchOptions) { 
    childList = new ArrayList<String>(); 
    for (String model : searchOptions) 
     childList.add(model); 
} 

回答

0

你必须在这里使用意图是在Android的意图的文档:

http://developer.android.com/guide/components/intents-filters.html

但基本上,你在那里有你不得不这样做的吐司:

Intent childIntent = new Intent(this, ChildActivity.class); 
startActivity(childIntent); 
+0

嗨,感谢您的反馈,我将如何指定我的孩子列表中的哪个项目将链接到新的活动? – rory 2015-01-21 01:10:05

+0

@rory你有一些数据绑定到你的子项目,你可以通过getChild(int groupPosition,int childPosition)获取数据,并将一些数据放入intent – jobcrazy 2015-01-21 01:21:36

+0

Hi @jobcrazy,我想要高度链接到一个新的活动 String []搜索= {“身高”,“体重”, “头发颜色”}; – rory 2015-01-21 01:28:07

0

要发送数据到新的Activity.You可以写这样的事情

Intent childIntent = new Intent(this, ChildActivity.class); 
childIntent.putExtra("bind_value", (String) expListAdapter.getChild(
        groupPosition, childPosition)); 
startActivity(childIntent); 

并检索新Activity的onCreate()中的值。

+0

谢谢,不幸的是,这给我一个错误无法解析构造函数:( – rory 2015-01-21 01:46:26

+0

发布更多关于您的错误? – jobcrazy 2015-01-21 01:47:58

+0

无法解析构造函数'Intent(android.widget.ExpandableListView.OnChildClickListener,java.lang.class – rory 2015-01-21 01:50:41

相关问题