2011-12-22 101 views
0

是否有可能返回一個視圖(ListView中的一行)?返回視圖(ListView)

我想禁用所有的複選框:

public void disableCheckboxes() 
{  
    for(int i =0; i < getCount(); i++) 
    { 
     View view = (View) getView(i, null, null); 
     CheckBox checkBox = (CheckBox)view.findViewById(R.id.playlist_checkbox); 
     checkBox.setVisibility(CheckBox.INVISIBLE); 
    } 
} 
+0

此問題是http://stackoverflow.com/questions/257514/android-access-child-views-from-a-listview的副本。請在那裏找到你的答案:) – 2011-12-22 09:41:36

回答

0

非常相似的功能,您可以在Robotium源代碼中找到,尤其是在類ViewFetcher。或者你可以使用Robotium。

public ArrayList<View> getAllViews(boolean onlySufficientlyVisible) { 
    final View[] views = getWindowDecorViews(); 
    final ArrayList<View> allViews = new ArrayList<View>(); 
    final View[] nonDecorViews = getNonDecorViews(views); 


    if (views != null && views.length > 0) { 
     View view; 
     for(int i = 0; i < nonDecorViews.length; i++){ 
      view = nonDecorViews[i]; 
      try { 
       addChildren(allViews, (ViewGroup)view, onlySufficientlyVisible); 
      } catch (Exception ignored) { 
      } 
     } 
     view = getRecentDecorView(views); 
     try { 
      addChildren(allViews, (ViewGroup)view, onlySufficientlyVisible); 
     } catch (Exception ignored) { 
     } 
    } 
    return allViews; 
}