Android ListView 按钮调用电话

标签 android android-intent

我正在尝试在我的 listView 项目上放置一个按钮并调用电话......但到目前为止,我无法弄清楚如何将该数据分配给该按钮操作,这是我的代码......列表项目本身是不可点击的,只有按钮是。我使用适配器从数组中获取数据

public View getView(int position, View convertView, ViewGroup parent)
{
    ViewHolder holder;
    //Get the current location object
    info lm = (info) getItem(position);

    //Inflate the view
    if(convertView==null)
    {
        convertView = dInflater.inflate(R.layout.dealbranch_layout, null);
        holder = new ViewHolder();
        holder.name = (TextView) convertView.findViewById(R.id.address);
        holder.call = (Button) convertView.findViewById(R.id.call);
        convertView.setTag(holder);
    }
    else
    {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.name.setText(lm.getName());


    holder.call.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {

        Intent call = new Intent (Itent.ACTION_CALL);

            ///  No clue.. >,<  ///  /// lm.getPhone() should get the phone# for this row.
            /// this action does not work   /////

        startActivity(call);
    }
    });

    return convertView;
}

如果有人能给我指路就好了。谢谢。

最佳答案

我们不知道您如何定义“信息”类,所以这是我的猜测:

首先,改变行:

info lm = (info) getItem(position);

final info lm = (info) getItem(position);

下面是如何使用电话号码调用 ACTION_DIAL:

holder.call.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {

    Intent call = new Intent (Intent.ACTION_DIAL, Uri.parse("tel:" + lm.getPhone()));

        ///  No clue.. >,<  ///  /// lm.getPhone() should get the phone# for this row.
        /// this action does not work   /////

    startActivity(call);
}

这是假设 lm.getPhone() 方法返回字符串中的电话号码。

关于Android ListView 按钮调用电话,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11480736/

相关文章:

java.lang.NoClassDefFoundError : android. support.v7.internal.widget.TintManager

java - 在 NavigationDrawer 中单击按钮打开 Activity

java - 无法解析方法 'startActivity(android.content.Intent); - 在安卓设备上打开 URL

android - 我需要帮助查找我的 Openshift MongoDB 的 url 或 IP 地址

android - 为 Android 转码和流式传输视频文件

java - 使用出生日期计算年龄

android - Firebase Analytics - app_open 包括收到的推送通知

java - 将字符串数组传递给另一个 Activity 以与 ion 一起使用

android - 无法使用 Chooser 使 startActivity() 每个应用只询问一次

android - 如何在 Android N 中更改多窗口显示的 View ?如何检查应用程序是否在多窗口中?