【问题标题】:Android - Launch Intent within ExpandableListViewAndroid - 在 ExpandableListView 中启动 Intent
【发布时间】:2010-05-28 16:19:34
【问题描述】:

我正在尝试确定是否可以在 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);

【问题讨论】:

    标签: android expandablelistview android-intent


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-21
      • 2016-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多