2016-05-26 73 views
0

我創建了一個簡單的Renderer,看起來像這樣渲染器獲得當前焦點

using Android.Runtime; 
using Android.Widget; 
using Example.Pages.MaterialPages; 
using Example.Droid.Renderers; 
using Xamarin.Forms; 
using Xamarin.Forms.Platform.Android; 

[assembly: ExportRenderer(typeof(MaterialsListView), typeof(MaterialsListViewRenderer))] 
namespace Example.Droid.Renderers 
{ 
    public class MaterialsListViewRenderer : ListViewRenderer 
    { 
     public MaterialsListViewRenderer() {} 
    } 

    internal class ScrollListener : Java.Lang.Object, AbsListView.IOnScrollListener 
    { 
     public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } 

     public void OnScrollStateChanged(AbsListView view, [GeneratedEnum] ScrollState scrollState) 
     { 
     if (scrollState == ScrollState.TouchScroll) 
     { 
      // GET THE CURRENT FOCUSED ELEMENT 
     } 
     } 
    } 
} 

現在我需要獲得當前焦點象Java getCurrentFocus。 但是我怎麼能在Xamarin中做到這一點?

回答

1

您需要投下ListViewContextActivity

internal class ScrollListener : Java.Lang.Object, AbsListView.IOnScrollListener 
{ 
    public void OnScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { } 

    public void OnScrollStateChanged(AbsListView view, [GeneratedEnum] ScrollState scrollState) 
    { 
     if (scrollState == ScrollState.TouchScroll) 
     { 
      // GET THE CURRENT FOCUSED ELEMENT 
      var focused = ((Activity) view.Context).CurrentFocus; 
     } 
    } 
}