Intent Chooser不会在单击时消失

时间:2014-02-22 12:59:12

标签: android android-intent xamarin.android xamarin

我正在创建一个Android应用程序,其中我在主屏幕上有LISTVIEW。与LISTVIEW关联的LISTITEM包含IMAGEVIEW(共享图标)。 LISTITEM的Onclick事件我试图显示意图选择器以分享LISTITEM的内容,但我的问题是,如果我不对屏幕上显示的INTENT选择器执行任何操作,如果我只是尝试按下硬件后退按钮,目前显示的意图选择器不会消失,它仍保留在屏幕上。按下后退按钮几次后,尝试3-4次后消失。我实际上并不想要这种不寻常的行为,它应该在第一次尝试时消失。

        public override View GetView (int position, View convertView, ViewGroup parent)
    {

        var item = items [position];
        View view = convertView;
        if (view == null)
            view = context.LayoutInflater.Inflate (Resource.Layout.HadithListViewItem, null);


        string HadithText = string.Empty;
        string BookName = string.Empty;
        string ChapterName = string.Empty;


        view.FindViewById<TextView> (Resource.Id.HadithText).Text = items [position].HadithText;


        HadithText = view.FindViewById<TextView> (Resource.Id.HadithText).Text;

        BookName = items[position].BookName;;
        ChapterName = items[position].ChapterName.ToString()+ "-" + items[position].HadithID.ToString();



        ImageView share = view.FindViewById<ImageView> (Resource.Id.ShareButton);

        share.Click += (object sender2, EventArgs e2) => {;

            Intent sharingIntent = new Intent(Android.Content.Intent.ActionSend); 
            sharingIntent.SetType("text/plain");


            String shareBody = HadithText;
            sharingIntent.PutExtra(Android.Content.Intent.ExtraSubject, BookName + "(" + ChapterName + ")\n");
            sharingIntent.PutExtra(Android.Content.Intent.ExtraText, shareBody);
            this.context.StartActivity(Intent.CreateChooser(sharingIntent, "Share via"));


        };


        view.FindViewById<TextView> (Resource.Id.HadithBook).Text = BookName;
        view.FindViewById<TextView>(Resource.Id.HadithChapter).Text = ChapterName;
        view.SetOnClickListener (null);



        return view;


    }

1 个答案:

答案 0 :(得分:0)

在我看来,就像你多次设置Click一样。我怀疑如果你将点击更改为等于,它应该正常工作,只启动onClick的单个实例。要测试它,请尝试在Click例程中记录一些内容。

share.Click = (object sender2, EventArgs e2)