Android / Java - 添加textView拖放GridView教程/示例 [英] Android / Java - Add textView to Drag-Drop GridView Tutorial / Example

查看:152
本文介绍了Android / Java - 添加textView拖放GridView教程/示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从以下教程中创建了一个基于几个类的项目:

I've create a project based on a few classes from the following tutorial:

http://blahti.wordpress.com/2012/03/03/improved-drag-drop-for-gridview/

现在我正在尝试修改示例,以便不仅可以拖放图像,而且可以同时拖放图像和textView。

Now I'm attempting to modify the example to be able to drag and drop not only an image - but an image and a textView at the same time.

如何实现?

我已经实例化了textView:

I've instantiated the textView already:

tx = (TextView) findViewById(R.id.textView1);   

现在我相信我需要修改教程的acceptDrop方法(在它的DropTarget类中),但是'不是100%肯定如何做到这一点。

Now I believe I'll need to modify the tutorial's acceptDrop method (in it's DropTarget class) but I'm not 100% sure how to do so.

底线:

我只需要一点了解如何添加一个textView到这个简单拖放gridView教程。

I simply need a bit of figuring out how to add a textView to this simple drag and drop gridView tutorial.

完整来源可以在这里查看和下载

Full source can be seen and downloaded here

https://docs.google.com/file/d/0B0wYSnCBkoR6MmdWbnktYUpTc2FFakdVU3NYeUxDZw/edit

PS

我在教程评论部分留下了评论,作者提到以下内容:

I left a comment regarding doing this in the tutorial's comment section and the author mentioned the following:

您将需要一个自定义类来定义gridview中的项目,该视图将显示文本和图像。让新类实现拖放界面,在acceptDrop方法中文本和图像。

"You will need to come up with a custom class to define the items that go in the gridview. That view would display the text and an image. Have the new class implement the drag-drop interfaces. In the acceptDrop method copy both the text and the image.

您遇到的问题的一部分类似于具有列表视图的自定义列表项,可能会发现几个示例在你进行拖放部分之前。

Part of the problem you face is similar to having a custom list item with a list view. It might be good to find a few examples of that before you take on the drag-drop part."

我只需要一点帮助,这样做...

I simply need a bit of help doing so...

/**
 * Interface defining an object that reacts to objects being dragged over and dropped onto it.
 *
 */
public interface DropTarget {

    /**
     * Handle an object being dropped on the DropTarget
     * 
     * @param source DragSource where the drag started
     * @param x X coordinate of the drop location
     * @param y Y coordinate of the drop location
     * @param xOffset Horizontal offset with the object being dragged where the original
     *          touch happened
     * @param yOffset Vertical offset with the object being dragged where the original
     *          touch happened
     * @param dragView The DragView that's being dragged around on screen.
     * @param dragInfo Data associated with the object being dragged
     * 
     */
    void onDrop(DragSource source, int x, int y, int xOffset, int yOffset,
            DragView dragView, Object dragInfo);

    /**
     * React to something started to be dragged.
     */    
    void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
            DragView dragView, Object dragInfo);

    /**
     * React to something being dragged over the drop target.
     */    
    void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
            DragView dragView, Object dragInfo);

    /**
     * React to a drag 
     */    
    void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
            DragView dragView, Object dragInfo);

    /**
     * Check if a drop action can occur at, or near, the requested location.
     * This may be called repeatedly during a drag, so any calls should return
     * quickly.
     * 
     * @param source DragSource where the drag started
     * @param x X coordinate of the drop location
     * @param y Y coordinate of the drop location
     * @param xOffset Horizontal offset with the object being dragged where the
     *            original touch happened
     * @param yOffset Vertical offset with the object being dragged where the
     *            original touch happened
     * @param dragView The DragView that's being dragged around on screen.
     * @param dragInfo Data associated with the object being dragged
     * @return True if the drop will be accepted, false otherwise.
     */
    boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
            DragView dragView, Object dragInfo);

    /**
     * Estimate the surface area where this object would land if dropped at the
     * given location.
     * 
     * @param source DragSource where the drag started
     * @param x X coordinate of the drop location
     * @param y Y coordinate of the drop location
     * @param xOffset Horizontal offset with the object being dragged where the
     *            original touch happened
     * @param yOffset Vertical offset with the object being dragged where the
     *            original touch happened
     * @param dragView The DragView that's being dragged around on screen.
     * @param dragInfo Data associated with the object being dragged
     * @param recycle {@link Rect} object to be possibly recycled.
     * @return Estimated area that would be occupied if object was dropped at
     *         the given location. Should return null if no estimate is found,
     *         or if this target doesn't provide estimations.
     */
    Rect estimateDropLocation(DragSource source, int x, int y, int xOffset, int yOffset,
            DragView dragView, Object dragInfo, Rect recycle);

    // These methods are implemented in Views
    void getHitRect(Rect outRect);
    void getLocationOnScreen(int[] loc);
    int getLeft();
    int getTop();
}


推荐答案

网格视图中的拖放可以在此链接上找到 http://www.androidviews.net/ 2012/12 / pageddragdropgrid /

Well the simple way to implement the drag drop in grid view can be found on this link http://www.androidviews.net/2012/12/pageddragdropgrid/

这个git为 https://github.com/mrKlar/PagedDragDropGrid

这篇关于Android / Java - 添加textView拖放GridView教程/示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆