Code example for ListView

Methods: measuregetChildAtlayoutsetAdapter

0
     * If a view in a ListView requests a layout it should be remeasured. 
     */ 
    @MediumTest 
    public void testRequestLayout() throws Exception { 
        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);
    } 
 
    /** 
     * The list view should handle the disappearance of the only selected item, even when that item 
Stop searching for code, let great code find you!  Add Codota to your java IDE