简体   繁体   English

C#-搜索TextView多行

[英]C# - Searching a TextView Multi-line

I have created a Multi Line TextView in C# using Xamarin but need some help with searching through it using the users input. 我已经使用Xamarin在C#中创建了多行TextView,但是在使用用户输入进行搜索时需要一些帮助。

This is the multi line textview - 这是多行textview-

           TextView productList1 = FindViewById<TextView>(Resource.Id.productList);

The Data - 数据 -

       productList1.Text += "Tomato Soup" + System.Environment.NewLine;
       productList1.Text += "Yo-yo" + System.Environment.NewLine;
       productList1.Text += "Hammer" + System.Environment.NewLine;

The statement which doesn't work - 无效的陈述-

if (productSearch.Text.Contains(productList1.ToString()) == true)
            {
               editingResult.Text = "Found";
            }

With productSearch being the users input and editingResult being a textview where the "Found" is being shown. 以productSearch为用户输入,editedResult为显示“ Found”的文本视图。

However, I can use this statement to search which works fine but I wish to search through the entire list not individually. 但是,我可以使用此语句进行搜索,效果很好,但我希望不单独搜索整个列表。

    if (productSearch.Text.Contains("Hammer") == true)
           {
               editingResult.Text = "Found";
            }

Any Ideas? 有任何想法吗?

Thank You 谢谢

Change your code to: 将您的代码更改为:

if (productList1.Text.Contains(productSearch.Text.ToString()))
{
     editingResult.Text = "Found";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM