开发者

Android - Launch Intent within ExpandableListView

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


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜