首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

listView焦点有关问题

2012-08-24 
listView焦点问题public void onItemSelected(AdapterView? listView, View view, int position, long i

listView焦点问题

public void onItemSelected(AdapterView<?> listView, View view, int position, long id)?
{?
? ? if (position == 1)?
? ? {?
? ? ? ? // listView.setItemsCanFocus(true);?
?
? ? ? ? // Use afterDescendants, because I don't want the ListView to steal focus?
? ? ? ? listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);?
? ? ? ? myEditText.requestFocus();?
? ? }?
? ? else?
? ? {?
? ? ? ? if (!listView.isFocused())?
? ? ? ? {?
? ? ? ? ? ? // listView.setItemsCanFocus(false);?
?
? ? ? ? ? ? // Use beforeDescendants so that the EditText doesn't re-take focus?
? ? ? ? ? ? listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);?
? ? ? ? ? ? listView.requestFocus();?
? ? ? ? }?
? ? }?
}?
?
public void onNothingSelected(AdapterView<?> listView)?
{?
? ? // This happens when you start scrolling, so we need to prevent it from staying?
? ? // in the afterDescendants mode if the EditText was focused ?
? ? listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS);?
}?

有时候根据需要 <ListView?
? ? android:id="@android:id/list" ?
? ? android:layout_height="fill_parent" ?
? ? android:layout_width="fill_parent"?
? ? android:descendantFocusability="beforeDescendants"?
? ? />?
主要是 android:descendantFocusability属性的使用

热点排行