1 /* 2 * Copyright (C) 2007 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 android.widget.listview; 18 19 import com.android.frameworks.coretests.R; 20 21 import android.app.ListActivity; 22 import android.database.Cursor; 23 import android.os.Bundle; 24 import android.provider.Contacts.People; 25 import android.view.animation.AlphaAnimation; 26 import android.view.animation.Animation; 27 import android.view.animation.AnimationSet; 28 import android.view.animation.LayoutAnimationController; 29 import android.view.animation.TranslateAnimation; 30 import android.widget.ListAdapter; 31 import android.widget.ListView; 32 import android.widget.SimpleCursorAdapter; 33 import android.widget.Toast; 34 35 /** 36 * See 1080989. You need some contacts for this adapter. 37 */ 38 public class ListWithDisappearingItemBug extends ListActivity { 39 40 @Override onCreate(Bundle savedInstanceState)41 protected void onCreate(Bundle savedInstanceState) { 42 super.onCreate(savedInstanceState); 43 44 Toast.makeText(this, "Make sure you rotate screen to see bug", Toast.LENGTH_LONG).show(); 45 46 // Get a cursor with all people 47 Cursor c = getContentResolver().query(People.CONTENT_URI, null, null, null, null); 48 startManagingCursor(c); 49 50 ListAdapter adapter = new SimpleCursorAdapter(this, 51 // Use a template that displays a text view 52 R.layout.list_with_disappearing_item_bug_item, 53 // Give the cursor to the list adatper 54 c, 55 // Map the NAME column in the people database to... 56 new String[] {People.NAME} , 57 // The "text1" view defined in the XML template 58 new int[] {R.id.text1}); 59 setListAdapter(adapter); 60 61 AnimationSet set = new AnimationSet(true); 62 63 Animation animation = new AlphaAnimation(0.0f, 1.0f); 64 animation.setDuration(50); 65 set.addAnimation(animation); 66 67 animation = new TranslateAnimation( 68 Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, 69 Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f 70 ); 71 animation.setDuration(100); 72 set.addAnimation(animation); 73 74 LayoutAnimationController controller = 75 new LayoutAnimationController(set, 0.5f); 76 ListView listView = getListView(); 77 listView.setLayoutAnimation(controller); 78 } 79 80 } 81