简体   繁体   English

C#Xamarin editText单击按钮,然后滚动到listview项,怎么办?

[英]C# Xamarin editText click on button and then scroll to listview item, how?

I made a huge listview list, now I want to make this user friendly. 我做了一个巨大的listview列表,现在我想使这个用户友好。 So when I type something in a edittext and when I click on the button: then It needs to scroll programmatically to the listview item. 因此,当我在edittext中键入内容并单击按钮时:然后它需要以编程方式滚动到listview项。 How can I do this? 我怎样才能做到这一点?

When you finish typing you need to search that text in your list and smoothscroll to that position. 键入完毕后,您需要在列表中搜索该文本并将其平滑滚动到该位置。

private ListView _listView;
private ArrayAdapter<string> _adapter;
private EditText _inputSearch;
private Button _buttonSearch;

protected override void OnCreate(Bundle bundle)
{
    base.OnCreate(bundle);    
    SetContentView(Resource.Layout.Main);

    string[] products = {"Winter Is Coming", "The Kingsroad", "Lord Snow", "Cripples, Bastards, and Broken Things", "The Wolf and the Lion", "A Golden Crown", "You Win or You Die", "The Pointy End", "Baelor", "Fire and Blood"};

    _listView = FindViewById<ListView>(Resource.Id.list_view);
    _inputSearch = FindViewById<EditText>(Resource.Id.inputSearch);
    _buttonSearch = FindViewById< EditText > (Resource.Id.btnSearch);
    _adapter = new ArrayAdapter<string>(this, Resource.Layout.list_item, Resource.Id.product_name, products);
    _listView.Adapter = _adapter;

    _buttonSearch.Click += (sender, e) => 
    {             
        var index = Array.FindIndex(products, i => i.Equals(_inputSearch.Text));
        _listView.SmoothScrollToPosition(index);
    };    
}

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

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