2012-01-11 52 views
0

我確實得到了拖放工作,並且TouchListView類很好用。然而,在我的情況下,由於我的適配器包含可以有多行的EditText,因此我有不同高度的行。因此,在我放下之後,我所有的行都轉換爲tlv:normal_height,在我的情況下是74dip。這會導致很多行切斷EditText中的所有文本。我嘗試重新初始化我的適配器(mylistview.setAdapter = myadapter),將ListView設置爲GONE,然後是VISIBLE和invalidateViews(),但似乎沒有任何事情將ListView重置爲拖動之前,離開活動並返回。這裏可以做些什麼? -ThxCommonsware Drag Drop永久收縮行高

tlv:normal_height="74dip" 
tlv:expanded_height="128dip" 

回答

0

有一點問題,原來的AOSP代碼是專爲統一的行高,整個expanded_height結構在那裏爲用戶可視化會在哪裏發生放置提供了空間。

一個起始點可能是創建一個TouchListAdapter混合接口(類似於SpinnerAdapter),其中normal_heightexpanded_height將基於position適配器動態檢索,而不是被固定在佈局中聲明的值。無論是單獨的還是足夠的或者更多的工作都需要完成,我不能說。

如果您想出解決方案,歡迎使用補丁。否則,我可能會在某個時候看看,但不是很快。

我對沒有近期銀彈的道歉表示歉意。

+0

我明白了,謝謝。我會看看是否可以編輯TouchListView類並查看是否可以根據ListView項目的高度動態設置行高。我假設我可以從TouchListView類訪問ListView的適配器 - 那麼你能指點我在代碼中的正確位置嗎? – Mike6679 2012-01-11 17:19:34

+0

@Mike:使用'getAdapter()'獲取適配器。 – CommonsWare 2012-01-11 17:21:25

0

我編輯了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); 
        } 
      } 
    }