Bauerca drag-sort-listview简单的例子
Bauerca drag-sort-listview是一个惊人的图书馆拖动function在列表视图.. https://github.com/bauerca/drag-sort-listview
但我的问题是演示项目是非常复杂的,我不能跟踪它包括在我的项目中的function..
任何简单的例子,将不胜感激..
例如,我只需要一个屏幕,这个自定义列表包含三个项目。或者任何其他简单的例子..
谢谢
下面是一个关于如何使用我自己编写的库的简短程序。 基本上和样本一样,只是在一个地方。
package com.example.dndlist; import java.util.ArrayList; import java.util.Arrays; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.widget.ArrayAdapter; import com.mobeta.android.dslv.DragSortController; import com.mobeta.android.dslv.DragSortListView; public class MainActivity extends Activity { DragSortListView listView; ArrayAdapter<String> adapter; private DragSortListView.DropListener onDrop = new DragSortListView.DropListener() { @Override public void drop(int from, int to) { if (from != to) { String item = adapter.getItem(from); adapter.remove(item); adapter.insert(item, to); } } }; private DragSortListView.RemoveListener onRemove = new DragSortListView.RemoveListener() { @Override public void remove(int which) { adapter.remove(adapter.getItem(which)); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listView = (DragSortListView) findViewById(R.id.listview); String[] names = getResources().getStringArray(R.array.random_names); ArrayList<String> list = new ArrayList<String>(Arrays.asList(names)); adapter = new ArrayAdapter<String>(this, R.layout.item_layout, R.id.textView1, list); listView.setAdapter(adapter); listView.setDropListener(onDrop); listView.setRemoveListener(onRemove); DragSortController controller = new DragSortController(listView); controller.setDragHandleId(R.id.imageView1); //controller.setClickRemoveId(R.id.); controller.setRemoveEnabled(false); controller.setSortEnabled(true); controller.setDragInitMode(1); //controller.setRemoveMode(removeMode); listView.setFloatViewManager(controller); listView.setOnTouchListener(controller); listView.setDragEnabled(true); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } }
布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:dslv="http://schemas.android.com/apk/res/com.example.dndlist" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context=".MainActivity" > <com.mobeta.android.dslv.DragSortListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_margin="10dp" android:dividerHeight="5dp" android:paddingBottom="0dp" android:paddingLeft="10dp" android:paddingTop="0dp" dslv:collapsed_height="2dp" dslv:drag_enabled="true" dslv:drag_handle_id="@drawable/drag_handle" dslv:drag_scroll_start="0.33" dslv:drag_start_mode="onMove" dslv:float_alpha="0.6" dslv:max_drag_scroll_speed="0.5" dslv:remove_enabled="true" dslv:remove_mode="flingRemove" dslv:slide_shuffle_speed="0.3" dslv:sort_enabled="true" dslv:track_drag_sort="false" dslv:use_default_controller="true" /> </RelativeLayout>