0

我试图弄清楚是否可以在 ExpandableListView 中启动意图。基本上,“组”之一是电话号码,它的孩子是号码。我希望用户能够单击它并让它自动呼叫该号码。这可能吗?如何?

这是我使用名为“数据”的地图填充 ExpandableListView 的代码。

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

1 回答 1

0

您可以将OnChildClickListener添加到可展开的列表视图中。调用 OnChildClick 时,您拥有组和子位置,因此您应该能够确定单击了哪个电话号码。

然后你只需要触发一个打电话的意图,即:

Intent intent = new Intent(Intent.CALL_ACTION);
intent.setData(Uri.parse("tel:+436641234567"));
startActivity(intent);
于 2010-05-28T16:47:55.457 回答