forked from bauerca/drag-sort-listview
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples in demo project for single- and multi-choice listview
- Loading branch information
Mattias Flodin
committed
Jan 8, 2013
1 parent
e42d7ab
commit 3a77411
Showing
8 changed files
with
224 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.mobeta.android.dslv.DragSortListView xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:dslv="http://schemas.android.com/apk/res/com.mobeta.android.demodslv" | ||
android:id="@android:id/list" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:layout_margin="3dp" | ||
android:choiceMode="multipleChoice" | ||
android:dividerHeight="1px" | ||
android:padding="3dp" | ||
dslv:click_remove_id="@id/click_remove" | ||
dslv:collapsed_height="1px" | ||
dslv:drag_enabled="true" | ||
dslv:drag_handle_id="@id/drag_handle" | ||
dslv:drag_scroll_start="0.33" | ||
dslv:drag_start_mode="onDown" | ||
dslv:float_alpha="0.6" | ||
dslv:remove_enabled="true" | ||
dslv:remove_mode="clickRemove" | ||
dslv:slide_shuffle_speed="0.3" /> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.mobeta.android.demodslv.CheckableLinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="@dimen/item_height" | ||
android:orientation="horizontal"> | ||
<ImageView | ||
android:id="@id/drag_handle" | ||
android:background="@drawable/drag" | ||
android:layout_width="wrap_content" | ||
android:layout_height="@dimen/item_height" | ||
android:layout_weight="0" /> | ||
<CheckedTextView | ||
android:checkMark="?android:attr/listChoiceIndicatorMultiple" | ||
android:id="@+id/text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="@dimen/item_height" | ||
android:layout_weight="1" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:gravity="center_vertical" | ||
android:paddingLeft="8dp" /> | ||
</com.mobeta.android.demodslv.CheckableLinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<com.mobeta.android.demodslv.CheckableLinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="fill_parent" | ||
android:layout_height="@dimen/item_height" | ||
android:orientation="horizontal"> | ||
<ImageView | ||
android:id="@id/drag_handle" | ||
android:background="@drawable/drag" | ||
android:layout_width="wrap_content" | ||
android:layout_height="@dimen/item_height" | ||
android:layout_weight="0" /> | ||
<CheckedTextView | ||
android:checkMark="?android:attr/listChoiceIndicatorSingle" | ||
android:id="@+id/text" | ||
android:layout_width="wrap_content" | ||
android:layout_height="@dimen/item_height" | ||
android:layout_weight="1" | ||
android:textAppearance="?android:attr/textAppearanceMedium" | ||
android:gravity="center_vertical" | ||
android:paddingLeft="8dp" /> | ||
</com.mobeta.android.demodslv.CheckableLinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
demo/src/com/mobeta/android/demodslv/CheckableLinearLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.mobeta.android.demodslv; | ||
|
||
import android.content.Context; | ||
import android.util.AttributeSet; | ||
import android.widget.Checkable; | ||
import android.widget.LinearLayout; | ||
|
||
public class CheckableLinearLayout extends LinearLayout implements Checkable { | ||
|
||
private static final int CHECKABLE_CHILD_INDEX = 1; | ||
private Checkable child; | ||
|
||
public CheckableLinearLayout(Context context, AttributeSet attrs) { | ||
super(context, attrs); | ||
} | ||
|
||
@Override | ||
protected void onFinishInflate() { | ||
super.onFinishInflate(); | ||
child = (Checkable) getChildAt(CHECKABLE_CHILD_INDEX); | ||
} | ||
|
||
@Override | ||
public boolean isChecked() { | ||
return child.isChecked(); | ||
} | ||
|
||
@Override | ||
public void setChecked(boolean checked) { | ||
child.setChecked(checked); | ||
} | ||
|
||
@Override | ||
public void toggle() { | ||
child.toggle(); | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
demo/src/com/mobeta/android/demodslv/MultipleChoiceListView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.mobeta.android.demodslv; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
import android.app.ListActivity; | ||
import android.os.Bundle; | ||
import android.widget.ArrayAdapter; | ||
|
||
import com.mobeta.android.dslv.DragSortListView; | ||
|
||
|
||
public class MultipleChoiceListView extends ListActivity | ||
{ | ||
private ArrayAdapter<String> adapter; | ||
|
||
private DragSortListView.DropListener onDrop = | ||
new DragSortListView.DropListener() { | ||
@Override | ||
public void drop(int from, int to) { | ||
if (from != to) { | ||
DragSortListView list = getListView(); | ||
String item = adapter.getItem(from); | ||
adapter.remove(item); | ||
adapter.insert(item, to); | ||
list.moveCheckState(from, to); | ||
} | ||
} | ||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.checkable_main); | ||
|
||
String[] array = getResources().getStringArray(R.array.jazz_artist_names); | ||
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(array)); | ||
|
||
adapter = new ArrayAdapter<String>(this, R.layout.list_item_checkable, R.id.text, arrayList); | ||
|
||
setListAdapter(adapter); | ||
|
||
DragSortListView list = getListView(); | ||
list.setDropListener(onDrop); | ||
} | ||
|
||
@Override | ||
public DragSortListView getListView() { | ||
return (DragSortListView) super.getListView(); | ||
} | ||
|
||
} |
56 changes: 56 additions & 0 deletions
56
demo/src/com/mobeta/android/demodslv/SingleChoiceListView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.mobeta.android.demodslv; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
|
||
import android.app.ListActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.widget.ArrayAdapter; | ||
import android.widget.ListView; | ||
|
||
import com.mobeta.android.dslv.DragSortListView; | ||
|
||
|
||
public class SingleChoiceListView extends ListActivity | ||
{ | ||
private ArrayAdapter<String> adapter; | ||
|
||
private DragSortListView.DropListener onDrop = | ||
new DragSortListView.DropListener() { | ||
@Override | ||
public void drop(int from, int to) { | ||
if (from != to) { | ||
DragSortListView list = getListView(); | ||
String item = adapter.getItem(from); | ||
adapter.remove(item); | ||
adapter.insert(item, to); | ||
list.moveCheckState(from, to); | ||
Log.d("DSLV", "Selected item is " + list.getCheckedItemPosition()); | ||
} | ||
} | ||
}; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.checkable_main); | ||
|
||
String[] array = getResources().getStringArray(R.array.jazz_artist_names); | ||
ArrayList<String> arrayList = new ArrayList<String>(Arrays.asList(array)); | ||
|
||
adapter = new ArrayAdapter<String>(this, R.layout.list_item_radio, R.id.text, arrayList); | ||
|
||
setListAdapter(adapter); | ||
|
||
DragSortListView list = getListView(); | ||
list.setDropListener(onDrop); | ||
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE); | ||
} | ||
|
||
@Override | ||
public DragSortListView getListView() { | ||
return (DragSortListView) super.getListView(); | ||
} | ||
|
||
} |