Array TextView点击拨打电话Xamarin Android

时间:2015-06-28 11:57:13

标签: c# android xamarin textview

我正在为我的学士学位开设移动应用程序,我正在尝试插入新功能,当有人点击textview中的号码来拨打该号码时。我写了下面的代码,我期待工作正常但我得到一个错误。有一个文本视图保存电话号码,但有多个人有电话号码。我认为,如果只有一个人有电话号码,那就好了。

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

PhoneNUmber1(textView3)

PhoneNUmber2(textView3)

PhoneNUmber3(textView3)

等等

错误:

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>

在视图中添加电话号码 - TextView

 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;
            });
        }

2 个答案:

答案 0 :(得分:1)

对于打算工作的电话,它必须如此:

$brand = filter_input(INPUT_GET, 'brand', FILTER_VALIDATE_INT);

如果这不起作用,那么我可能需要了解有关该应用程序的更多内容:

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

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

使用文本填充textViews的电话号码的格式是什么?

答案 1 :(得分:0)

对于Android Xamarin

RunOnUiThread(()=> mylabel.Text =“从其他线程更新”);

快乐编码:-)