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' をどのように定義しているのかわかりませんので、私の推測は次のとおりです。

まず、次の行を変更します。

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 に答える