Android DragNDrop列表视图在片段中崩溃
我希望这有点明显。我尝试将所有内容更改回常规的“listView”(而不是使用DragNDragList库),但它仍然崩溃 我试着用一些通用的示例资源来替换这些东西,但还是失败了。 我觉得ListViewCursorAdaptor中有一些基本的东西我忽略了,这是导致崩溃的原因,我的问题并不是dragNdrop库独有的 问题是否与它是一个片段有关 我的onCreateView:Android DragNDrop列表视图在片段中崩溃,android,listview,android-fragments,Android,Listview,Android Fragments,我希望这有点明显。我尝试将所有内容更改回常规的“listView”(而不是使用DragNDragList库),但它仍然崩溃 我试着用一些通用的示例资源来替换这些东西,但还是失败了。 我觉得ListViewCursorAdaptor中有一些基本的东西我忽略了,这是导致崩溃的原因,我的问题并不是dragNdrop库独有的 问题是否与它是一个片段有关 我的onCreateView: myFragmentView = inflater.inflate(R.layout.todo_fragment, co
myFragmentView = inflater.inflate(R.layout.todo_fragment, container, false);
db = new DBAdapter(getActivity());
db.open();
Cursor TaskCursor = db.getAllTasks();
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
Log.d("cursor", TaskCursor.getString(1)); //This shows me that my cursor obviously isn't empty
adapter = new DragNDropCursorAdapter(myFragmentView.getContext(),
R.layout.task_list_item,
TaskCursor,
new String[]{DBAdapter.COLUMN_NAME},
new int[]{R.id.TaskItemTitle},
R.id.DragHandle);
Log.d("apater", "test");
list.setDragNDropAdapter(adapter); //Line 46 (where it crashes)
Log.d("apater", "test");
db.close();
return myFragmentView;
我的列表片段:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<com.terlici.dragndroplist.DragNDropListView
android:id="@+id/dragList"
android:layout_width="match_parent"
android:layout_height="match_parent"
/></LinearLayout>
您的日志表明它是一个空点异常,并且在listview中。请尝试替换
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
到
您使用的是getactivity()请在您的案例中使用膨胀视图名称,它是myFragmentView这就是发生空点异常的原因。您在日志中说它是空点异常,它在listview中。请尝试替换
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
到
您使用的是getactivity()请在您的案例中使用膨胀视图名称,它是myFragmentView这就是发生空点异常的原因。您在日志中说它是空点异常,它在listview中。请尝试替换
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
到
您使用的是getactivity()请在您的案例中使用膨胀视图名称,它是myFragmentView这就是发生空点异常的原因。您在日志中说它是空点异常,它在listview中。请尝试替换
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
到
您使用的是getactivity()请在您的案例中使用膨胀视图名称,因为它是myFragmentView,这就是发生空点异常的原因。您需要将下面的代码移到onViewCreated()。我猜findViewById返回null,因为视图仍在创建中
db = new DBAdapter(getActivity());
db.open();
Cursor TaskCursor = db.getAllTasks();
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
Log.d("cursor", TaskCursor.getString(1)); //This shows me that my cursor obviously isn't empty
adapter = new DragNDropCursorAdapter(myFragmentView.getContext(),
R.layout.task_list_item,
TaskCursor,
new String[]{DBAdapter.COLUMN_NAME},
new int[]{R.id.TaskItemTitle},
R.id.DragHandle);
Log.d("apater", "test");
list.setDragNDropAdapter(adapter); //Line 46 (where it crashes)
Log.d("apater", "test");
db.close();
替换
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
借
您需要将下面的代码移动到onViewCreated()。我猜findViewById返回null,因为视图仍在创建中
db = new DBAdapter(getActivity());
db.open();
Cursor TaskCursor = db.getAllTasks();
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
Log.d("cursor", TaskCursor.getString(1)); //This shows me that my cursor obviously isn't empty
adapter = new DragNDropCursorAdapter(myFragmentView.getContext(),
R.layout.task_list_item,
TaskCursor,
new String[]{DBAdapter.COLUMN_NAME},
new int[]{R.id.TaskItemTitle},
R.id.DragHandle);
Log.d("apater", "test");
list.setDragNDropAdapter(adapter); //Line 46 (where it crashes)
Log.d("apater", "test");
db.close();
替换
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
借
您需要将下面的代码移动到onViewCreated()。我猜findViewById返回null,因为视图仍在创建中
db = new DBAdapter(getActivity());
db.open();
Cursor TaskCursor = db.getAllTasks();
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
Log.d("cursor", TaskCursor.getString(1)); //This shows me that my cursor obviously isn't empty
adapter = new DragNDropCursorAdapter(myFragmentView.getContext(),
R.layout.task_list_item,
TaskCursor,
new String[]{DBAdapter.COLUMN_NAME},
new int[]{R.id.TaskItemTitle},
R.id.DragHandle);
Log.d("apater", "test");
list.setDragNDropAdapter(adapter); //Line 46 (where it crashes)
Log.d("apater", "test");
db.close();
替换
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
借
您需要将下面的代码移动到onViewCreated()。我猜findViewById返回null,因为视图仍在创建中
db = new DBAdapter(getActivity());
db.open();
Cursor TaskCursor = db.getAllTasks();
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
Log.d("cursor", TaskCursor.getString(1)); //This shows me that my cursor obviously isn't empty
adapter = new DragNDropCursorAdapter(myFragmentView.getContext(),
R.layout.task_list_item,
TaskCursor,
new String[]{DBAdapter.COLUMN_NAME},
new int[]{R.id.TaskItemTitle},
R.id.DragHandle);
Log.d("apater", "test");
list.setDragNDropAdapter(adapter); //Line 46 (where it crashes)
Log.d("apater", "test");
db.close();
替换
list = (DragNDropListView) getActivity().findViewById(R.id.dragList);
借
是的,就是这样。非常感谢。是的,就是这样。非常感谢。是的,就是这样。非常感谢。是的,就是这样。非常感谢。