我編輯了unExpandViews()方法 - 稱爲getAdapter(),並且對於我的適配器中的每個項目,將高度設置爲0,然後將所有行設置回原始。我也繞過了刪除部分的方法,因爲它不適用於我。
private void unExpandViews(boolean deletion) {
int height_saved = 0;
CheckBoxifiedTextListAdapter cbla = (CheckBoxifiedTextListAdapter)getAdapter();
for (int i = 0;i < cbla.getCount(); i++)
{
//View v = getChildAt(i);
View v = cbla.getView(i, null, null);
//if (v == null)
//{
/*
if (deletion)
{
// HACK force update of mItemCount
int position = getFirstVisiblePosition();
int y = getChildAt(0).getTop();
setAdapter(getAdapter());
setSelectionFromTop(position, y);
// end hack
}
layoutChildren(); // force children to be recreated where needed
v = getChildAt(i);
if (v == null)
{
break;
}
height_saved = v.getHeight();
*/
//}
//else
//height_saved = v.getHeight();
if (isDraggableRow(v))
{
ViewGroup.LayoutParams params = v.getLayoutParams();
params.height = 0;
v.setLayoutParams(params);
v.setVisibility(View.VISIBLE);
}
}
}
我明白了,謝謝。我會看看是否可以編輯TouchListView類並查看是否可以根據ListView項目的高度動態設置行高。我假設我可以從TouchListView類訪問ListView的適配器 - 那麼你能指點我在代碼中的正確位置嗎? – Mike6679 2012-01-11 17:19:34
@Mike:使用'getAdapter()'獲取適配器。 – CommonsWare 2012-01-11 17:21:25