2016-06-20 4 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

관련 문제