返回视图(ListView)
问题描述:
是否有可能返回一个视图(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);
}
}
答
非常相似的功能,您可以在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;
}
此问题是http://stackoverflow.com/questions/257514/android-access-child-views-from-a-listview的副本。请在那里找到你的答案:) – 2011-12-22 09:41:36