2012-01-11 53 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); 
        } 
      } 
    }