2016-09-21 5 views

答えて

19

ViewGroupとその子孫との関係を定義し、フォーカスを取得する場合はViewを探します。

次の定数のいずれかである必要があります。

 
+------------------------------------------------------------------------------------------+ 
|  Constant   Value   Description         | 
+------------------------------------------------------------------------------------------+ 
| afterDescendants   1   The ViewGroup will get focus only if    | 
|          none of its descendants want it.     | 
+------------------------------------------------------------------------------------------+ 
| beforeDescendants   0   The ViewGroup will get focus before    | 
|          any of its descendants.       | 
+------------------------------------------------------------------------------------------+ 
| blocksDescendants   2   The ViewGroup will block its descendants from  | 
|          receiving focus.         | 
+------------------------------------------------------------------------------------------+ 

完全な例hereを確認できます。

断片である:上記のスニペット1として

public void onItemSelected(AdapterView<?> parent, View view, 
     int position, long id) { 
    ListView listView = getListView(); 
    Log.d(TAG, "onItemSelected gave us " + view.toString()); 
    Button b = (Button) view.findViewById(R.id.button); 
    EditText et = (EditText) view.findViewById(R.id.editor); 
    if (b != null || et != null) { 
     // Use afterDescendants to keep ListView from getting focus 
     listView.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); 
     if(et!=null) et.requestFocus(); 
     else if(b!=null) b.requestFocus(); 
    } else { 
     if (!listView.isFocused()) { 
      // Use beforeDescendants so that previous selections don't re-take focus 
      listView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); 
      listView.requestFocus(); 
     } 
    } 

} 

afterDescendantsEditText又はButtonいずれかがフォーカスを要求することができるように、フォーカスを得ることからlistviewを防止するために使用されます。

関連する問題