Code example for ListView

Methods: layoutaddHeaderViewsetAdaptersetSelection, measure

0
     * 
     */ 
    @MediumTest 
    public void testNoSelectableItems() throws Exception { 
        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);
    } 
 
    private class MockContext2 extends MockContext {
 
        @Override