Android的列表视图按钮拨打电话 [英] Android List View Button make a call

查看:122
本文介绍了Android的列表视图按钮拨打电话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图把我的ListView项按钮并拨打电话......但到目前为止,我无法弄清楚如何将数据分配到该按钮的动作,这里是我的code ..该列表项本身无法点击,只有按钮。我使用适配器从数组中获取数据

i am trying to put a button on my listView item and make a call... but so far, I couldn't figure out how to assign that data to that button action and here is my code... The list item itself is not clickable, only the button is. I use an adapter to get the data from the array

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

将是巨大的,如果有人可以告诉我的方式。谢谢你。

Would be great if someone could show me the way. Thanks.

推荐答案

我们不知道你是怎么定义类信息所以这里是我的猜测:

We don't know how you define the class 'info' so here's my guess:

首先,更改行:

info lm = (info) getItem(position);

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

然后在这里是如何使用的电话号码调用ACTION_DIAL:

then here's how to invoke ACTION_DIAL with phone number:

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()方法返回字符串的电话号码。

This is assuming the lm.getPhone() method returns a phone number in string.

这篇关于Android的列表视图按钮拨打电话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆