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属性的使用

你可能感兴趣的:(android)