2010-05-28 7 views
0

J'essaie de déterminer s'il est possible de lancer une intention dans une ExpandableListView. Fondamentalement, l'un des "Groupes" est numéro de téléphone et son enfant est le numéro. Je veux que l'utilisateur puisse cliquer dessus et l'appeler automatiquement. Est-ce possible? Comment?Android - Intention de lancement dans ExpandableListView

Voici mon code pour remplir ExpandableListView en utilisant une carte appelée "données".

ExpandableListView myList = (ExpandableListView) findViewById(R.id.myList); 
       //ExpandableListAdapter adapter = new MyExpandableListAdapter(data); 
       List<Map<String, String>> groupData = new ArrayList<Map<String, String>>(); 
       List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>(); 

       Iterator it = data.entrySet().iterator(); 
       while (it.hasNext()) 
       { 
        //Get the key name and value for it 
        Map.Entry pair = (Map.Entry)it.next(); 
        String keyName = (String) pair.getKey(); 
        String value = pair.getValue().toString(); 

        //Add the parents -- aka main categories 
        Map<String, String> curGroupMap = new HashMap<String, String>(); 
        groupData.add(curGroupMap); 
        curGroupMap.put("NAME", keyName); 

        //Add the child data 
        List<Map<String, String>> children = new ArrayList<Map<String, String>>(); 
        Map<String, String> curChildMap = new HashMap<String, String>(); 
        children.add(curChildMap); 
        curChildMap.put("NAME", value); 

        childData.add(children); 

       } 

       // Set up our adapter 
       mAdapter = new SimpleExpandableListAdapter(
         mContext, 
         groupData, 
         R.layout.exp_list_parent, 
         new String[] { "NAME", "IS_EVEN" }, 
         new int[] { R.id.rowText1, R.id.rowText2 }, 
         childData, 
         R.layout.exp_list_child, 
         new String[] { "NAME", "IS_EVEN" }, 
         new int[] { R.id.rowText3, R.id.rowText4} 
         ); 

       myList.setAdapter(mAdapter); 

Répondre

0

Vous pouvez ajouter un OnChildClickListener à votre vue liste extensible. Lorsque OnChildClick est appelé, vous avez la position du groupe et de l'enfant, donc vous devriez être capable de déterminer quel numéro de téléphone a été cliqué.

Ensuite il vous suffit de déclencher l'intention de faire l'appel téléphonique, i.e. .:

Intent intent = new Intent(Intent.CALL_ACTION); 
intent.setData(Uri.parse("tel:+436641234567")); 
startActivity(intent); 
+0

Merci pour votre aide! – Ryan