1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.example.android.listviewdragginganimation; 18 19 import android.app.Activity; 20 import android.os.Bundle; 21 import android.widget.ListView; 22 23 import java.util.ArrayList; 24 25 /** 26 * This application creates a listview where the ordering of the data set 27 * can be modified in response to user touch events. 28 * 29 * An item in the listview is selected via a long press event and is then 30 * moved around by tracking and following the movement of the user's finger. 31 * When the item is released, it animates to its new position within the listview. 32 */ 33 public class ListViewDraggingAnimation extends Activity { 34 35 @Override 36 protected void onCreate(Bundle savedInstanceState) { 37 super.onCreate(savedInstanceState); 38 setContentView(R.layout.activity_list_view); 39 40 ArrayList<String>mCheeseList = new ArrayList<String>(); 41 for (int i = 0; i < Cheeses.sCheeseStrings.length; ++i) { 42 mCheeseList.add(Cheeses.sCheeseStrings[i]); 43 } 44 45 StableArrayAdapter adapter = new StableArrayAdapter(this, R.layout.text_view, mCheeseList); 46 DynamicListView listView = (DynamicListView) findViewById(R.id.listview); 47 48 listView.setCheeseList(mCheeseList); 49 listView.setAdapter(adapter); 50 listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); 51 } 52 } 53