2015-01-21 27 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

相關問題