1

我正在尝试在我的 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;
}

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

4

1 回答 1

3

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

首先,换行:

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

于 2012-07-14T04:36:07.590 回答