【发布时间】:2015-06-07 06:51:10
【问题描述】:
更新: 要理解我的问题,这是我需要实现的目标: 将图标从应用程序抽屉拖到主屏幕(如果可能不在网格视图中),就像图片中一样,
旧的(这只是为了了解它是如何工作的):
我正在尝试实现将可点击图标从ListView 拖动到customView,在同一个Activity 或另一个Activity 中没有容器(Listview or Gridview...),这里有一张图片供您了解更多:
但是当我将图标放在右侧区域时我看不到对象,在日志中我看到:I/ViewRootImpl﹕ Reporting drop result: true
这是我的代码:
class MyDragListener implements View.OnDragListener {
@Override
public boolean onDrag(View v, DragEvent event) {
int action = event.getAction();
switch (event.getAction()) {
...
case DragEvent.ACTION_DROP:
LinearLayoutAbsListView itemo = (LinearLayoutAbsListView)findViewById(R.id.paneko);
View child = getLayoutInflater().inflate(R.layout.list_item, null);
itemo.addView(child);
break;
case DragEvent.ACTION_DRAG_ENDED:
default:
break;
}
return true;
}
}
我的 XML 文件:
...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:background="@android:color/background_dark"
android:orientation="horizontal" >
<com.moapps.elfassimounir.simple.LinearLayoutAbsListView
android:id="@+id/paneuj"
android:background="@android:color/background_light"
android:orientation="vertical"
>
<ListView
android:id="@+id/listview1"
android:layout_width="100dp"
android:layout_height="wrap_content" />
</com.moapps.elfassimounir.simple.LinearLayoutAbsListView>
<com.moapps.elfassimounir.simple.LinearLayoutAbsListView
android:id="@+id/paneko"
android:background="@android:color/background_light"
android:orientation="vertical" >
</com.moapps.elfassimounir.simple.LinearLayoutAbsListView>
</LinearLayout>
...
任何信息或参考资料(教程、文档...)都会非常有帮助
【问题讨论】:
-
这一行你在做什么 LinearLayoutAbsListView newParent = (LinearLayoutAbsListView)v; ,v是ID为pane3的视图吗?如果是这样,当没有为此视图定义列表视图时,您如何设置此视图的适配器?
-
不,此代码与 Listview 一起使用只是为了让您了解我做了什么
-
LinearLayoutAbsListView 中的 v 是什么 newParent = (LinearLayoutAbsListView)v;关于你的 xml
-
是的@random v 是ID为pane3的视图
-
您能否确认passedItem 是否被添加到destList 并且newParent.absListView 是否引用了pane3 中的listview?
标签: java android view drag-and-drop layout-inflater