I need to implement something like this. I just want to show max. 3 or 4 items at a time and rest of the items should be scrollable.
If i have a total of 10 items in the dropdown, then only the 4 items should be visible at a time in the dropdown, and the other 6 items should be visible on scrolling down
Can any one help me i have stuck i have converted but still not able to limit height of spinner dropdown item and scroll its content
public class CompoundCodeView: Spinner,IJavaObject
{
Context mContext;
public CompoundCodeView(Context context) :
base(context)
{
init(context);
}
public CompoundCodeView(Context context, IAttributeSet attrs) :
base(context, attrs)
{
init(context);
}
public CompoundCodeView(Context context, IAttributeSet attrs, int defStyle) :
base(context, attrs, defStyle)
{
init(context);
}
private void init(Context ctx)
{
mContext = ctx;
}
public override bool PerformClick()
{
bool bClicked = base.PerformClick();
try
{
// Class klass = Class.FromType(typeof(Spinner));
var klass = Java.Lang.Class.FromType(typeof(Spinner));
var mPopupField = klass.GetDeclaredField("mPopup");
mPopupField.Accessible=true;
ListPopupWindow pop = (ListPopupWindow)mPopupField.Get(this);
ListView listview = pop.ListView;
var vklass = Java.Lang.Class.FromType(typeof(View));
var mScrollCacheField = vklass.GetDeclaredField("mScrollCache");
mScrollCacheField.Accessible=true;
Java.Lang.Object mScrollCache = mScrollCacheField.Get(listview);
var temp = mScrollCache.Class;
Field scrollBarField= temp.GetDeclaredField("scrollBar");
scrollBarField.Accessible = true;
Java.Lang.Object scrollBar = scrollBarField.Get(mScrollCache);
Method method = scrollBar.Class.GetDeclaredMethod("setVerticalThumbDrawable",Class.FromType(typeof(Drawable)) );
method.Accessible = true;
method.Invoke(scrollBar,Resources.GetDrawable(Resource.Drawable.scrollbar_style));
if (VERSION.SdkInt >= VERSION_CODES.Honeycomb)
{
var vlass = Java.Lang.Class.FromType(typeof(View));
var mVerticalScrollbarPositionField = vlass.GetDeclaredField("mVerticalScrollbarPosition");
mVerticalScrollbarPositionField.Accessible=true;
mVerticalScrollbarPositionField.Set(listview,Left);
}
}
catch (Java.Lang.Exception e)
{
// e.StackTrace;
}
return base.PerformClick();
}
}
}