1

我试图为我的 Fragment 实现 DragListener,但应用程序崩溃并在此行上给我一个 NoClassDefFoundError:

findViewById(R.id.my_tab_fragment).setOnDragListener(new MyDragListener());

这是我的片段:

public class MainFragmentActivity extends FragmentActivity {


    @Override    
    protected void onCreate(Bundle bundle) {   

        WWHApplication.getInstance().getJsonDBInstance();
        WWHApplication.checkDB();

        super.onCreate(bundle);
        setContentView(R.layout.main_fragment_activity_drag);

        findViewById(R.id.my_tab_fragment).setOnDragListener(new MyDragListener());


            }


            class MyDragListener implements OnDragListener {
                //Drawable enterShape = getResources().getDrawable(
                    //  R.drawable.shape_droptarget);
                //Drawable normalShape = getResources().getDrawable(R.drawable.shape);

                @Override
                public boolean onDrag(View v, DragEvent event) {
                    switch (event.getAction()) {
                    case DragEvent.ACTION_DRAG_STARTED:
                        // Do nothing
                        break;
                    case DragEvent.ACTION_DRAG_ENTERED:
                        //v.setBackgroundDrawable(enterShape);
                        break;
                    case DragEvent.ACTION_DRAG_EXITED:
                        //v.setBackgroundDrawable(normalShape);
                        break;
                    case DragEvent.ACTION_DROP:
                        // Dropped, reassign View to ViewGroup
                        //View view = (View) event.getLocalState();
                        //ViewGroup owner = (ViewGroup) view.getParent();
                        //owner.removeView(view);
                        //LinearLayout container = (LinearLayout) v;
                        //container.addView(view);
                        //view.setVisibility(View.VISIBLE);
                        break;
                    case DragEvent.ACTION_DRAG_ENDED:
                        //v.setBackgroundDrawable(normalShape);
                    default:
                        break;
                    }
                    return true;
                }
            }
    }

我需要做什么来修复错误?谢谢

4

1 回答 1

2

如果你在你的设备上运行它,你应该检查它的 API 级别。如果它运行的是 2.2.x(API 级别 8),则不能使用拖放,因为它需要 API 11

于 2012-06-26T05:53:50.173 回答