FileDocCategorySizeDatePackage
ListViewTest.javaAPI DocAndroid 1.5 API4603Wed May 06 22:42:02 BST 2009com.android.frameworktest.widget

ListViewTest

public class ListViewTest extends android.test.InstrumentationTestCase
Copyright (C) 2007 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Fields Summary
Constructors Summary
Methods Summary
public voidtestNoSelectableItems()
The list view should handle the disappearance of the only selected item, even when that item was selected before its disappearance.

        MockContext context = new MockContext2();
        ListView listView = new ListView(context);
        // We use a header as the unselectable item to remain after the selectable one is removed.
        listView.addHeaderView(new View(context), null, false);
        List<String> items = Lists.newArrayList("hello");
        Adapter<String> adapter = new Adapter<String>(context, 0, items);
        listView.setAdapter(adapter);

        listView.setSelection(1);

        int measureSpec = View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY);

        adapter.notifyDataSetChanged();
        listView.measure(measureSpec, measureSpec);
        listView.layout(0, 0, 100, 100);

        items.remove(0);

        adapter.notifyDataSetChanged();
        listView.measure(measureSpec, measureSpec);
        listView.layout(0, 0, 100, 100);
    
public voidtestRequestLayout()
If a view in a ListView requests a layout it should be remeasured.

        MockContext context = new MockContext2();
        ListView listView = new ListView(context);
        List<String> items = Lists.newArrayList("hello");
        Adapter<String> adapter = new Adapter<String>(context, 0, items);
        listView.setAdapter(adapter);

        int measureSpec = View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY);

        adapter.notifyDataSetChanged();
        listView.measure(measureSpec, measureSpec);
        listView.layout(0, 0, 100, 100);

        MockView childView = (MockView) listView.getChildAt(0);

        childView.requestLayout();
        childView.onMeasureCalled = false;
        listView.measure(measureSpec, measureSpec);
        listView.layout(0, 0, 100, 100);
        Assert.assertTrue(childView.onMeasureCalled);