数组文本视图点击呼叫电话Xamarin Android

本文关键字:电话 Xamarin Android 呼叫 文本 视图 数组 | 更新日期: 2023-09-27 18:00:04

我正在为我的学士学位开发一个移动应用程序,当有人点击文本视图中的号码拨打该号码时,我正试图插入一个新功能。我写了下面的代码,我本来希望能很好地工作,但我遇到了一个错误。有一个文本视图保存电话号码,但有多个人拥有电话号码。我想,如果只有一个人有电话号码,那也没关系。

这就是电话号码列表的样子-全部在textView3

电话号码1(文本视图3)

电话号码2(文本视图3)

电话号码3(文本视图3)

等等

错误:

06-28 13:48:49.574 I/MonoDroid(30648): UNHANDLED EXCEPTION:
06-28 13:48:49.584 I/MonoDroid(30648): System.NullReferenceException: Object reference not set to an instance of an object

OnCreate函数中MainActivy中的代码是

 TextView txtViewTel = FindViewById<TextView>(Resource.Id.textView3);
    string stringtelefon = txtViewTel.ToString();
//          Toast.MakeText(this, stringtelefon, ToastLength.Short).Show();

    txtViewTel.Click += delegate
    {
      var uri = Android.Net.Uri.Parse(stringtelefon);
      var intent = new Intent(Intent.ActionDial, uri);
      StartActivity(intent);
    };

textView3是一个文本视图,它具有阵列中每个客户端的电话号码。

AXML是

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:weightSum="100"
    android:background="#F1F1F1">
    <ImageView
        android:id="@+id/imgPic"
        android:src="@drawable/icon_client"
        android:layout_width="0dp"
        android:layout_weight="25"
        android:layout_height="match_parent"
        android:background="#3B5998"
        android:adjustViewBounds="true"
        android:scaleType="center"
        android:layoutDirection="inherit" />
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="65">
        <TextView
            android:id="@+id/textView1"
            android:text="Nume Client"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="65"
            android:gravity="center"
            android:textSize="18sp"
            android:textColor="#000" />
        <TextView
            android:id="@+id/textView2"
            android:text="Prenume Client"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="65"
            android:gravity="center"
            android:textSize="18sp"
            android:textColor="#000" />
        <TextView
            android:id="@+id/textView3"
            android:text="Telefon"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="65"
            android:gravity="center"
            android:textSize="18sp"
            android:textColor="#000"
            android:layout_marginRight="1.3dp"
            android:clickable="true" />
    </LinearLayout>
    <CheckBox
        android:id="@+id/btnStar"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="10"
        android:button="@android:drawable/btn_star"
        android:checked="false" />
</LinearLayout>

在视图中添加电话号码-文本视图

 public override View GetView(int position, View convertView, ViewGroup parent)
        {
            View row = convertView;
            if (row == null)
            {
                row = LayoutInflater.From(mContext).Inflate(mLayout, parent, false);
            }
            row.FindViewById<TextView>(Resource.Id.textView1).Text = mClient[position].NumeClient;
            row.FindViewById<TextView>(Resource.Id.textView2).Text = mClient[position].PrenumeClient;
            row.FindViewById<TextView>(Resource.Id.textView3).Text = mClient[position].TelClient;
            ImageView pic = row.FindViewById<ImageView>(Resource.Id.imgPic);
            if (mClient[position].Image != null)
            {
                pic.SetImageBitmap(BitmapFactory.DecodeByteArray(mClient[position].Image, 0, mClient[position].Image.Length));
            }
            pic.Tag = position;
            pic.Click -= pic_Click;
            pic.Click += pic_Click;
            return row;
        }

用数据库中的数据反序列化JSON以填充ListView

private void webClient_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
        {
            RunOnUiThread(() =>
            {
                string json = Encoding.UTF8.GetString(e.Result);
          List<Client> mClient = JsonConvert.DeserializeObject<List<Client>>(json);
                Action<ImageView> action = PicSelected;
                mAdapter = new ClientiListAdapter(this, Resource.Layout.ListaClienti, mClient, action);
                mListView.Adapter = mAdapter;
            });
        }

数组文本视图点击呼叫电话Xamarin Android

要想让电话工作,它必须是这样的:

Uri.parse("tel:" + stringtelefon)

如果这不起作用,那么我可能需要更多地了解这个应用程序:

您是否还在列表视图中使用xaml中的布局?

异常是从哪里调用的,应该是行号?

您在文本视图中填充的电话号码的格式是什么?

适用于Android Xamarin

RunOnUiThread(()=>mylabel。Text="从其他线程更新")

快乐编码:-)