views:

245

answers:

1

Hello,

I'm trying to figure out if it is possible to launch an intent within an ExpandableListView. Basically one of the "Groups" is Phone Number and its child is the number. I want the user to be able to click it and have it automatically call that number. Is this possible? How?

Here is my code to populate the ExpandableListView using a Map called "data".

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);
A: 

You can add an OnChildClickListener to your expandable list view. When OnChildClick is called, you have the group and child position, so you should be able to figure out which phone number was clicked.

Then you just need to fire off an intent to make the phone call, i.e.:

Intent intent = new Intent(Intent.CALL_ACTION);
intent.setData(Uri.parse("tel:+436641234567"));
startActivity(intent);
Mayra
Thanks for you help!
Ryan