Android的列表视图按钮拨打电话(Android List View Button make a

2019-10-17 00:22发布

我试图把我的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;
}

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

Answer 1:

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

首先,更改行:

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 List View Button make a call