【问题标题】:how can i use the number from textfield of each row in listview and make a call on this number?如何使用列表视图中每一行的文本字段中的号码并拨打该号码?
【发布时间】:2023-04-11 11:28:01
【问题描述】:

这是我的自定义适配器。

public View getView(int position, View convertView, ViewGroup parent) {
    LayoutInflater inflater= (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View row=inflater.inflate(R.layout.single_row, parent, false);
    ImageView myImage= (ImageView) row.findViewById(R.id.imageView);
    TextView myNames= (TextView) row.findViewById(R.id.contact_name);
    TextView myNumbers= (TextView) row.findViewById(R.id.contact_num);
    Button btn= (Button) row.findViewById(R.id.caller_button);
    myImage.setImageResource(images[position]);
    myNames.setText(nameArray[position]);
    myNumbers.setText(numberArray[position]);
    btn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

        }
    });
    return row;
}
}

【问题讨论】:

  • 你的问题不清楚:'(
  • 您已经有了要检测的每一行的位置,因此您可以调用指定位置的任何项目。
  • 我创建了一个列表视图,每行包含一个名称、一个电话号码和一个按钮。我想通过按下按钮拨打该号码。
  • 所以这是你的电话号码在你的 onClick() 中调用它:“numberArray[position]”

标签: android listview


【解决方案1】:

这是我的工作:

private class MyAdapter extends BaseAdapter {
   private ListView listView;
   ...
   @Override
   public View getView(int i, View view, ViewGroup viewGroup) {
      this.listView = (ListView) viewGroup;

然后在每个View.OnClickListener我可以通过

@Override
public void onClick(View view) {
   ...
   MyAdapter.this.listView.getPositionForView((View) view.getParent()));

【讨论】:

    【解决方案2】:

    在适配器getView方法中使用这个:

    yourViewHolder.callBtn.setOnClickListener(new View.OnClickListener(View view){
    
    String callNum=yourViewHolder.textField.getText().toString();
    String callUri="tel:"+callNum;
    Intent callIntent = new Intent(Intent.ACTION_CALL);
        callIntent.setData(Uri.parse(callUri));
        startActivity(callIntent);
    }
    );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多