2016-06-20 11 views
0

私は巨大なリストビューのリストを作ったので、このユーザーフレンドリーにしたいと思います。だから、私はedittextに何かを入力し、ボタンをクリックすると:プログラムでリストビュー項目にスクロールする必要があります。これどうやってするの?C#Xamarin editTextボタンをクリックして、リストビュー項目までスクロールします。

+0

あなたはsmoothscrollbyoffset方法を試みることができる、あなたはここでdocumenationを見つけることができ、https://developer.xamarin.com/api/member/Android.Widget.ListView.SmoothScrollByOffset/p/System.Int32/どのよう – Bearcat9425

+0

このメソッドは動作しますか? – Test

+0

SmoothScrollByオフセットはint型ですが、テキストアイテムにアクセスする必要があります。 – Test

答えて

0

入力が終了したら、リスト内のテキストを検索し、スムーズスクロールしてその位置に移動する必要があります。

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

あなたのコードをありがとう!私は学校でこの水曜日をテストするので、あなたは私から聞くでしょう。 – Test

+0

私の答えに間違いはないと思います。 – jzeferino

+0

私はそれを水曜日に試してみるつもりです。それが仕事になると、私はそれをマークします。 – Test

関連する問題