下面列出了怎么用android.widget.AbsSpinner的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Set Count of the Widget
*
* @param v
* Widget
* @param wd
* WidgetDescription instance
*/
@SuppressWarnings("rawtypes")
public static void setCount(View v, WidgetDescription w) {
// For lists, the count is set to the number of rows in the list
// (inactive rows - e.g. separators - count as well)
if (v instanceof AdapterView) {
w.setCount(((AdapterView) v).getCount());
return;
}
// For Spinners, the count is set to the number of options
if (v instanceof AbsSpinner) {
w.setCount(((AbsSpinner) v).getCount());
return;
}
// For the tab layout host, the count is set to the number of tabs
if (v instanceof TabHost) {
w.setCount(((TabHost) v).getTabWidget().getTabCount());
return;
}
// For grids, the count is set to the number of icons, for RadioGroups
// it's set to the number of RadioButtons
if (v instanceof ViewGroup) {
w.setCount(((ViewGroup) v).getChildCount());
return;
}
// For progress bars, seek bars and rating bars, the count is set to the
// maximum value allowed
if (v instanceof ProgressBar) {
w.setCount(((ProgressBar) v).getMax());
return;
}
}
/**
* Set Count of the Widget
*
* @param v
* Widget
* @param wd
* WidgetDescription instance
*/
@SuppressWarnings("rawtypes")
public static void setCount(View v, WidgetDescription w) {
// For lists, the count is set to the number of rows in the list
// (inactive rows - e.g. separators - count as well)
if (v instanceof AdapterView) {
w.setCount(((AdapterView) v).getCount());
return;
}
// For Spinners, the count is set to the number of options
if (v instanceof AbsSpinner) {
w.setCount(((AbsSpinner) v).getCount());
return;
}
// For the tab layout host, the count is set to the number of tabs
if (v instanceof TabHost) {
w.setCount(((TabHost) v).getTabWidget().getTabCount());
return;
}
// For grids, the count is set to the number of icons, for RadioGroups
// it's set to the number of RadioButtons
if (v instanceof ViewGroup) {
w.setCount(((ViewGroup) v).getChildCount());
return;
}
// For progress bars, seek bars and rating bars, the count is set to the
// maximum value allowed
if (v instanceof ProgressBar) {
w.setCount(((ProgressBar) v).getMax());
return;
}
}
/**
* Set Count of the Widget
*
* @param v
* Widget
* @param w
* WidgetDescription instance
*/
@SuppressWarnings("rawtypes")
public static void setCount(View v, WidgetDescription w) {
// For lists, the count is set to the number of rows in the list
// (inactive rows - e.g. separators - count as well)
if (v instanceof AdapterView) {
w.setCount(((AdapterView) v).getCount());
return;
}
// For Spinners, the count is set to the number of options
if (v instanceof AbsSpinner) {
w.setCount(((AbsSpinner) v).getCount());
return;
}
// For the tab layout host, the count is set to the number of tabs
if (v instanceof TabHost) {
w.setCount(((TabHost) v).getTabWidget().getTabCount());
return;
}
// For grids, the count is set to the number of icons, for RadioGroups
// it's set to the number of RadioButtons
if (v instanceof ViewGroup) {
w.setCount(((ViewGroup) v).getChildCount());
return;
}
// For progress bars, seek bars and rating bars, the count is set to the
// maximum value allowed
if (v instanceof ProgressBar) {
w.setCount(((ProgressBar) v).getMax());
return;
}
}
public static BaseDSL.ViewClassResult absSpinner() {
return BaseDSL.v(AbsSpinner.class);
}
public static Void absSpinner(Anvil.Renderable r) {
return BaseDSL.v(AbsSpinner.class, r);
}
public static BaseDSL.ViewClassResult absSpinner() {
return BaseDSL.v(AbsSpinner.class);
}
public static Void absSpinner(Anvil.Renderable r) {
return BaseDSL.v(AbsSpinner.class, r);
}
public void assertItem(final int spinnerId, final int position) {
final AbsSpinner view = (AbsSpinner) get(spinnerId);
assertEquals("Incorrect item selected: expected " + position + " but got " + view.getSelectedItemPosition(), position, view.getSelectedItemPosition());
}
@OnItemSelected(2) void selectAbsSpinner(AbsSpinner view) {
last = view;
}
@OnItemSelected(value = 2, callback = NOTHING_SELECTED)
void clearAbsSpinner(AbsSpinner view) {
last = view;
}
@OnItemClick(2) void itemClickAbsSpinner(AbsSpinner view) {
last = view;
}
@OnItemLongClick(2) boolean itemLongClickAbsSpinner(AbsSpinner view) {
last = view;
return true;
}
public AbsSpinnerAssert(AbsSpinner actual) {
super(actual, AbsSpinnerAssert.class);
}
/**
* Sets given item.
*
* @param spinnerId
* the spinner id
* @param position
* the item position.
*/
public void setItem(final int spinnerId, final int position) {
final AbsSpinner view = (AbsSpinner) get(spinnerId);
view.setSelection(position);
}