1 /* 2 * Copyright (C) 2008 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.cts; 18 19 import static org.junit.Assert.assertEquals; 20 import static org.junit.Assert.assertFalse; 21 import static org.junit.Assert.assertNotNull; 22 import static org.junit.Assert.assertNull; 23 import static org.junit.Assert.assertSame; 24 import static org.junit.Assert.assertTrue; 25 import static org.junit.Assert.fail; 26 import static org.mockito.Mockito.any; 27 import static org.mockito.Mockito.eq; 28 import static org.mockito.Mockito.mock; 29 import static org.mockito.Mockito.reset; 30 import static org.mockito.Mockito.times; 31 import static org.mockito.Mockito.verify; 32 import static org.mockito.Mockito.verifyZeroInteractions; 33 34 import android.app.Instrumentation; 35 import android.content.Context; 36 import android.database.DataSetObserver; 37 import android.graphics.Canvas; 38 import android.graphics.drawable.BitmapDrawable; 39 import android.graphics.drawable.Drawable; 40 import android.os.Parcelable; 41 import android.util.AttributeSet; 42 import android.util.Xml; 43 import android.view.LayoutInflater; 44 import android.view.View; 45 import android.view.ViewGroup; 46 import android.widget.ExpandableListAdapter; 47 import android.widget.ExpandableListView; 48 import android.widget.ListAdapter; 49 import android.widget.TextView; 50 import android.widget.cts.util.ExpandableListScenario; 51 52 import androidx.test.InstrumentationRegistry; 53 import androidx.test.annotation.UiThreadTest; 54 import androidx.test.filters.MediumTest; 55 import androidx.test.rule.ActivityTestRule; 56 import androidx.test.runner.AndroidJUnit4; 57 58 import com.android.compatibility.common.util.PollingCheck; 59 import com.android.compatibility.common.util.WidgetTestUtils; 60 61 import org.junit.Before; 62 import org.junit.Rule; 63 import org.junit.Test; 64 import org.junit.runner.RunWith; 65 import org.xmlpull.v1.XmlPullParser; 66 67 @MediumTest 68 @RunWith(AndroidJUnit4.class) 69 public class ExpandableListViewTest { 70 private Instrumentation mInstrumentation; 71 private ExpandableListScenario mActivity; 72 private ExpandableListView mExpandableListView; 73 74 @Rule 75 public ActivityTestRule<ExpandableList> mActivityRule = 76 new ActivityTestRule<>(ExpandableList.class); 77 78 @Before setup()79 public void setup() { 80 mInstrumentation = InstrumentationRegistry.getInstrumentation(); 81 mActivity = mActivityRule.getActivity(); 82 PollingCheck.waitFor(mActivity::hasWindowFocus); 83 mExpandableListView = mActivity.getExpandableListView(); 84 } 85 86 @Test testConstructor()87 public void testConstructor() { 88 new ExpandableListView(mActivity); 89 90 new ExpandableListView(mActivity, null); 91 92 new ExpandableListView(mActivity, null, android.R.attr.expandableListViewStyle); 93 94 new ExpandableListView(mActivity, null, 0, 95 android.R.style.Widget_DeviceDefault_ExpandableListView); 96 97 new ExpandableListView(mActivity, null, 0, 98 android.R.style.Widget_DeviceDefault_Light_ExpandableListView); 99 100 new ExpandableListView(mActivity, null, 0, 101 android.R.style.Widget_Material_ExpandableListView); 102 103 new ExpandableListView(mActivity, null, 0, 104 android.R.style.Widget_Material_Light_ExpandableListView); 105 106 XmlPullParser parser = 107 mActivity.getResources().getXml(R.layout.expandablelistview_layout); 108 AttributeSet attrs = Xml.asAttributeSet(parser); 109 new ExpandableListView(mActivity, attrs); 110 new ExpandableListView(mActivity, attrs, 0); 111 } 112 113 @Test(expected=NullPointerException.class) testConstructorWithNullContext1()114 public void testConstructorWithNullContext1() { 115 new ExpandableListView(null); 116 } 117 118 @Test(expected=NullPointerException.class) testConstructorWithNullContext2()119 public void testConstructorWithNullContext2() { 120 new ExpandableListView(null, null); 121 } 122 123 @Test(expected=NullPointerException.class) testConstructorWithNullContext3()124 public void testConstructorWithNullContext3() { 125 new ExpandableListView(null, null, 0); 126 } 127 128 @Test testSetChildDivider()129 public void testSetChildDivider() { 130 Drawable drawable = mActivity.getResources().getDrawable(R.drawable.scenery); 131 mExpandableListView.setChildDivider(drawable); 132 } 133 134 @Test(expected=RuntimeException.class) testSetAdapterOfWrongType()135 public void testSetAdapterOfWrongType() { 136 mExpandableListView.setAdapter((ListAdapter) null); 137 } 138 139 @UiThreadTest 140 @Test testGetAdapter()141 public void testGetAdapter() { 142 assertNull(mExpandableListView.getAdapter()); 143 144 ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter(); 145 mExpandableListView.setAdapter(expandableAdapter); 146 assertNotNull(mExpandableListView.getAdapter()); 147 } 148 149 @UiThreadTest 150 @Test testAccessExpandableListAdapter()151 public void testAccessExpandableListAdapter() { 152 ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter(); 153 154 assertNull(mExpandableListView.getExpandableListAdapter()); 155 mExpandableListView.setAdapter(expandableAdapter); 156 assertSame(expandableAdapter, mExpandableListView.getExpandableListAdapter()); 157 } 158 159 @UiThreadTest 160 @Test testPerformItemClick()161 public void testPerformItemClick() { 162 assertFalse(mExpandableListView.performItemClick(null, 100, 99)); 163 164 ExpandableListView.OnItemClickListener mockOnItemClickListener = 165 mock(ExpandableListView.OnItemClickListener.class); 166 mExpandableListView.setOnItemClickListener(mockOnItemClickListener); 167 assertTrue(mExpandableListView.performItemClick(null, 100, 99)); 168 verify(mockOnItemClickListener, times(1)).onItemClick(eq(mExpandableListView), 169 any(), eq(100), eq(99L)); 170 } 171 172 @Test testSetOnItemClickListener()173 public void testSetOnItemClickListener() { 174 ExpandableListView.OnItemClickListener mockOnItemClickListener = 175 mock(ExpandableListView.OnItemClickListener.class); 176 177 assertNull(mExpandableListView.getOnItemClickListener()); 178 mExpandableListView.setOnItemClickListener(mockOnItemClickListener); 179 assertSame(mockOnItemClickListener, mExpandableListView.getOnItemClickListener()); 180 } 181 182 @UiThreadTest 183 @Test testExpandGroup()184 public void testExpandGroup() { 185 ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter(); 186 mExpandableListView.setAdapter(expandableAdapter); 187 188 ExpandableListView.OnGroupExpandListener mockOnGroupExpandListener = 189 mock(ExpandableListView.OnGroupExpandListener.class); 190 mExpandableListView.setOnGroupExpandListener(mockOnGroupExpandListener); 191 192 verifyZeroInteractions(mockOnGroupExpandListener); 193 194 assertTrue(mExpandableListView.expandGroup(0)); 195 verify(mockOnGroupExpandListener, times(1)).onGroupExpand(0); 196 assertTrue(mExpandableListView.isGroupExpanded(0)); 197 198 reset(mockOnGroupExpandListener); 199 assertFalse(mExpandableListView.expandGroup(0)); 200 verify(mockOnGroupExpandListener, times(1)).onGroupExpand(0); 201 assertTrue(mExpandableListView.isGroupExpanded(0)); 202 203 reset(mockOnGroupExpandListener); 204 assertTrue(mExpandableListView.expandGroup(1)); 205 verify(mockOnGroupExpandListener, times(1)).onGroupExpand(1); 206 assertTrue(mExpandableListView.isGroupExpanded(1)); 207 208 reset(mockOnGroupExpandListener); 209 assertFalse(mExpandableListView.expandGroup(1)); 210 verify(mockOnGroupExpandListener, times(1)).onGroupExpand(1); 211 assertTrue(mExpandableListView.isGroupExpanded(1)); 212 213 reset(mockOnGroupExpandListener); 214 mExpandableListView.setAdapter((ExpandableListAdapter) null); 215 try { 216 mExpandableListView.expandGroup(0); 217 fail("should throw NullPointerException"); 218 } catch (NullPointerException e) { 219 } 220 } 221 222 @Test testExpandGroupSmooth()223 public void testExpandGroupSmooth() throws Throwable { 224 mActivityRule.runOnUiThread( 225 () -> mExpandableListView.setAdapter(new MockExpandableListAdapter())); 226 227 ExpandableListView.OnGroupExpandListener mockOnGroupExpandListener = 228 mock(ExpandableListView.OnGroupExpandListener.class); 229 mExpandableListView.setOnGroupExpandListener(mockOnGroupExpandListener); 230 231 verifyZeroInteractions(mockOnGroupExpandListener); 232 WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mExpandableListView, 233 () -> assertTrue(mExpandableListView.expandGroup(0, true))); 234 verify(mockOnGroupExpandListener, times(1)).onGroupExpand(0); 235 assertTrue(mExpandableListView.isGroupExpanded(0)); 236 237 reset(mockOnGroupExpandListener); 238 WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mExpandableListView, 239 () -> assertFalse(mExpandableListView.expandGroup(0, true))); 240 verify(mockOnGroupExpandListener, times(1)).onGroupExpand(0); 241 assertTrue(mExpandableListView.isGroupExpanded(0)); 242 243 reset(mockOnGroupExpandListener); 244 WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mExpandableListView, 245 () -> assertTrue(mExpandableListView.expandGroup(1, true))); 246 verify(mockOnGroupExpandListener, times(1)).onGroupExpand(1); 247 assertTrue(mExpandableListView.isGroupExpanded(1)); 248 249 reset(mockOnGroupExpandListener); 250 WidgetTestUtils.runOnMainAndDrawSync(mActivityRule, mExpandableListView, 251 () -> assertFalse(mExpandableListView.expandGroup(1, true))); 252 verify(mockOnGroupExpandListener, times(1)).onGroupExpand(1); 253 assertTrue(mExpandableListView.isGroupExpanded(1)); 254 255 reset(mockOnGroupExpandListener); 256 mActivityRule.runOnUiThread(() -> { 257 mExpandableListView.setAdapter((ExpandableListAdapter) null); 258 try { 259 mExpandableListView.expandGroup(0); 260 fail("should throw NullPointerException"); 261 } catch (NullPointerException e) { 262 } 263 }); 264 } 265 266 @UiThreadTest 267 @Test testCollapseGroup()268 public void testCollapseGroup() { 269 ExpandableListAdapter expandableAdapter = new MockExpandableListAdapter(); 270 mExpandableListView.setAdapter(expandableAdapter); 271 272 ExpandableListView.OnGroupCollapseListener mockOnGroupCollapseListener = 273 mock(ExpandableListView.OnGroupCollapseListener.class); 274 mExpandableListView.setOnGroupCollapseListener(mockOnGroupCollapseListener); 275 276 verifyZeroInteractions(mockOnGroupCollapseListener); 277 assertFalse(mExpandableListView.collapseGroup(0)); 278 verify(mockOnGroupCollapseListener, times(1)).onGroupCollapse(0); 279 assertFalse(mExpandableListView.isGroupExpanded(0)); 280 281 reset(mockOnGroupCollapseListener); 282 mExpandableListView.expandGroup(0); 283 assertTrue(mExpandableListView.collapseGroup(0)); 284 verify(mockOnGroupCollapseListener, times(1)).onGroupCollapse(0); 285 assertFalse(mExpandableListView.isGroupExpanded(0)); 286 287 reset(mockOnGroupCollapseListener); 288 assertFalse(mExpandableListView.collapseGroup(1)); 289 verify(mockOnGroupCollapseListener, times(1)).onGroupCollapse(1); 290 assertFalse(mExpandableListView.isGroupExpanded(1)); 291 292 reset(mockOnGroupCollapseListener); 293 mExpandableListView.setAdapter((ExpandableListAdapter) null); 294 try { 295 mExpandableListView.collapseGroup(0); 296 fail("should throw NullPointerException"); 297 } catch (NullPointerException e) { 298 } 299 } 300 301 @UiThreadTest 302 @Test testSetOnGroupClickListener()303 public void testSetOnGroupClickListener() { 304 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 305 306 ExpandableListView.OnGroupClickListener mockOnGroupClickListener = 307 mock(ExpandableListView.OnGroupClickListener.class); 308 309 mExpandableListView.setOnGroupClickListener(mockOnGroupClickListener); 310 verifyZeroInteractions(mockOnGroupClickListener); 311 312 mExpandableListView.performItemClick(null, 0, 0); 313 verify(mockOnGroupClickListener, times(1)).onGroupClick(eq(mExpandableListView), 314 any(), eq(0), eq(0L)); 315 } 316 317 @UiThreadTest 318 @Test testSetOnChildClickListener()319 public void testSetOnChildClickListener() { 320 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 321 322 ExpandableListView.OnChildClickListener mockOnChildClickListener = 323 mock(ExpandableListView.OnChildClickListener.class); 324 325 mExpandableListView.setOnChildClickListener(mockOnChildClickListener); 326 verifyZeroInteractions(mockOnChildClickListener); 327 328 // first let the list expand 329 mExpandableListView.expandGroup(0); 330 // click on the child list of the first group 331 mExpandableListView.performItemClick(null, 1, 0); 332 verify(mockOnChildClickListener, times(1)).onChildClick(eq(mExpandableListView), 333 any(), eq(0), eq(0), eq(0L)); 334 } 335 336 @UiThreadTest 337 @Test testGetExpandableListPosition()338 public void testGetExpandableListPosition() { 339 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 340 341 assertEquals(0, mExpandableListView.getExpandableListPosition(0)); 342 343 // Group 0 is not expanded, position 1 is invalid 344 assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL, 345 mExpandableListView.getExpandableListPosition(1)); 346 347 // Position 1 becomes valid when group 0 is expanded 348 mExpandableListView.expandGroup(0); 349 assertEquals(ExpandableListView.getPackedPositionForChild(0, 0), 350 mExpandableListView.getExpandableListPosition(1)); 351 352 // Position 2 is still invalid (only one child). 353 assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL, 354 mExpandableListView.getExpandableListPosition(2)); 355 } 356 357 @UiThreadTest 358 @Test testGetFlatListPosition()359 public void testGetFlatListPosition() { 360 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 361 362 try { 363 mExpandableListView.getFlatListPosition(ExpandableListView.PACKED_POSITION_VALUE_NULL); 364 } catch (NullPointerException e) { 365 } 366 assertEquals(0, mExpandableListView.getFlatListPosition( 367 ExpandableListView.PACKED_POSITION_TYPE_CHILD<<32)); 368 // 0x8000000100000000L means this is a child and group position is 1. 369 assertEquals(1, mExpandableListView.getFlatListPosition(0x8000000100000000L)); 370 } 371 372 @UiThreadTest 373 @Test testGetSelectedPosition()374 public void testGetSelectedPosition() { 375 assertEquals(ExpandableListView.PACKED_POSITION_VALUE_NULL, 376 mExpandableListView.getSelectedPosition()); 377 378 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 379 380 mExpandableListView.setSelectedGroup(0); 381 assertEquals(0, mExpandableListView.getSelectedPosition()); 382 383 mExpandableListView.setSelectedGroup(1); 384 assertEquals(0, mExpandableListView.getSelectedPosition()); 385 } 386 387 @UiThreadTest 388 @Test testGetSelectedId()389 public void testGetSelectedId() { 390 assertEquals(-1, mExpandableListView.getSelectedId()); 391 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 392 393 mExpandableListView.setSelectedGroup(0); 394 assertEquals(0, mExpandableListView.getSelectedId()); 395 396 mExpandableListView.setSelectedGroup(1); 397 assertEquals(0, mExpandableListView.getSelectedId()); 398 } 399 400 @UiThreadTest 401 @Test testSetSelectedGroup()402 public void testSetSelectedGroup() { 403 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 404 405 mExpandableListView.setSelectedGroup(0); 406 assertEquals(0, mExpandableListView.getSelectedPosition()); 407 408 mExpandableListView.setSelectedGroup(1); 409 assertEquals(0, mExpandableListView.getSelectedPosition()); 410 } 411 412 @UiThreadTest 413 @Test testSetSelectedChild()414 public void testSetSelectedChild() { 415 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 416 417 assertTrue(mExpandableListView.setSelectedChild(0, 0, false)); 418 assertTrue(mExpandableListView.setSelectedChild(0, 1, true)); 419 } 420 421 @UiThreadTest 422 @Test testIsGroupExpanded()423 public void testIsGroupExpanded() { 424 mExpandableListView.setAdapter(new MockExpandableListAdapter()); 425 426 mExpandableListView.expandGroup(1); 427 assertFalse(mExpandableListView.isGroupExpanded(0)); 428 assertTrue(mExpandableListView.isGroupExpanded(1)); 429 } 430 431 @Test testGetPackedPositionType()432 public void testGetPackedPositionType() { 433 assertEquals(ExpandableListView.PACKED_POSITION_TYPE_NULL, 434 ExpandableListView.getPackedPositionType( 435 ExpandableListView.PACKED_POSITION_VALUE_NULL)); 436 437 assertEquals(ExpandableListView.PACKED_POSITION_TYPE_GROUP, 438 ExpandableListView.getPackedPositionType(0)); 439 440 // 0x8000000000000000L is PACKED_POSITION_MASK_TYPE, but it is private, 441 // so we just use its value. 442 assertEquals(ExpandableListView.PACKED_POSITION_TYPE_CHILD, 443 ExpandableListView.getPackedPositionType(0x8000000000000000L)); 444 } 445 446 @Test testGetPackedPositionGroup()447 public void testGetPackedPositionGroup() { 448 assertEquals(-1, ExpandableListView.getPackedPositionGroup( 449 ExpandableListView.PACKED_POSITION_VALUE_NULL)); 450 451 assertEquals(0, ExpandableListView.getPackedPositionGroup(0)); 452 453 // 0x123400000000L means its group position is 0x1234 454 assertEquals(0x1234, ExpandableListView.getPackedPositionGroup(0x123400000000L)); 455 456 // 0x7FFFFFFF00000000L means its group position is 0x7FFFFFFF 457 assertEquals(0x7FFFFFFF, ExpandableListView.getPackedPositionGroup(0x7FFFFFFF00000000L)); 458 } 459 460 @Test testGetPackedPositionChild()461 public void testGetPackedPositionChild() { 462 assertEquals(-1, ExpandableListView.getPackedPositionChild( 463 ExpandableListView.PACKED_POSITION_VALUE_NULL)); 464 465 assertEquals(-1, ExpandableListView.getPackedPositionChild(1)); 466 467 // 0x8000000000000000L means its child position is 0 468 assertEquals(0, ExpandableListView.getPackedPositionChild(0x8000000000000000L)); 469 470 // 0x80000000ffffffffL means its child position is 0xffffffff 471 assertEquals(0xffffffff, ExpandableListView.getPackedPositionChild(0x80000000ffffffffL)); 472 } 473 474 @Test testGetPackedPositionForChild()475 public void testGetPackedPositionForChild() { 476 assertEquals(0x8000000000000000L, 477 ExpandableListView.getPackedPositionForChild(0, 0)); 478 479 assertEquals(0xffffffffffffffffL, 480 ExpandableListView.getPackedPositionForChild(Integer.MAX_VALUE, 0xffffffff)); 481 } 482 483 @Test testGetPackedPositionForGroup()484 public void testGetPackedPositionForGroup() { 485 assertEquals(0, ExpandableListView.getPackedPositionForGroup(0)); 486 487 assertEquals(0x7fffffff00000000L, 488 ExpandableListView.getPackedPositionForGroup(Integer.MAX_VALUE)); 489 } 490 491 @Test testSetChildIndicator()492 public void testSetChildIndicator() { 493 mExpandableListView.setChildIndicator(null); 494 } 495 496 @Test testSetChildIndicatorBounds()497 public void testSetChildIndicatorBounds() { 498 mExpandableListView.setChildIndicatorBounds(10, 20); 499 } 500 501 @Test testSetChildIndicatorBoundsRelative()502 public void testSetChildIndicatorBoundsRelative() { 503 mExpandableListView.setChildIndicatorBoundsRelative(10, 20); 504 } 505 506 @Test testSetGroupIndicator()507 public void testSetGroupIndicator() { 508 Drawable drawable = new BitmapDrawable(); 509 mExpandableListView.setGroupIndicator(drawable); 510 } 511 512 @Test testSetIndicatorBounds()513 public void testSetIndicatorBounds() { 514 mExpandableListView.setIndicatorBounds(10, 30); 515 } 516 517 @Test testSetIndicatorBoundsRelative()518 public void testSetIndicatorBoundsRelative() { 519 mExpandableListView.setIndicatorBoundsRelative(10, 30); 520 } 521 522 @Test testOnSaveInstanceState()523 public void testOnSaveInstanceState() { 524 ExpandableListView src = new ExpandableListView(mActivity); 525 Parcelable p1 = src.onSaveInstanceState(); 526 527 ExpandableListView dest = new ExpandableListView(mActivity); 528 dest.onRestoreInstanceState(p1); 529 Parcelable p2 = dest.onSaveInstanceState(); 530 531 assertNotNull(p1); 532 assertNotNull(p2); 533 } 534 535 @Test testDispatchDraw()536 public void testDispatchDraw() { 537 MockExpandableListView expandableListView = new MockExpandableListView(mActivity); 538 expandableListView.dispatchDraw(new Canvas()); 539 } 540 541 private class MockExpandableListAdapter implements ExpandableListAdapter { 542 private final LayoutInflater mLayoutInflater; 543 MockExpandableListAdapter()544 public MockExpandableListAdapter() { 545 mLayoutInflater = LayoutInflater.from(mActivity); 546 } 547 registerDataSetObserver(DataSetObserver observer)548 public void registerDataSetObserver(DataSetObserver observer) { 549 } 550 unregisterDataSetObserver(DataSetObserver observer)551 public void unregisterDataSetObserver(DataSetObserver observer) { 552 } 553 getGroupCount()554 public int getGroupCount() { 555 return 1; 556 } 557 getChildrenCount(int groupPosition)558 public int getChildrenCount(int groupPosition) { 559 switch (groupPosition) { 560 case 0: 561 return 1; 562 default: 563 return 0; 564 } 565 } 566 getGroup(int groupPosition)567 public Object getGroup(int groupPosition) { 568 switch (groupPosition) { 569 case 0: 570 return "Data"; 571 default: 572 return null; 573 } 574 } 575 getChild(int groupPosition, int childPosition)576 public Object getChild(int groupPosition, int childPosition) { 577 if (groupPosition == 0 && childPosition == 0) 578 return "child data"; 579 else 580 return null; 581 } 582 getGroupId(int groupPosition)583 public long getGroupId(int groupPosition) { 584 return 0; 585 } 586 getChildId(int groupPosition, int childPosition)587 public long getChildId(int groupPosition, int childPosition) { 588 return 0; 589 } 590 hasStableIds()591 public boolean hasStableIds() { 592 return true; 593 } 594 getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent)595 public View getGroupView(int groupPosition, boolean isExpanded, 596 View convertView, ViewGroup parent) { 597 TextView result = (TextView) convertView; 598 if (result == null) { 599 result = (TextView) mLayoutInflater.inflate( 600 R.layout.expandablelistview_group, parent, false); 601 } 602 result.setText("Group " + groupPosition); 603 return result; 604 } 605 getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent)606 public View getChildView(int groupPosition, int childPosition, 607 boolean isLastChild, View convertView, ViewGroup parent) { 608 TextView result = (TextView) convertView; 609 if (result == null) { 610 result = (TextView) mLayoutInflater.inflate( 611 R.layout.expandablelistview_child, parent, false); 612 } 613 result.setText("Child " + childPosition); 614 return result; 615 } 616 isChildSelectable(int groupPosition, int childPosition)617 public boolean isChildSelectable(int groupPosition, int childPosition) { 618 return true; 619 } 620 areAllItemsEnabled()621 public boolean areAllItemsEnabled() { 622 return true; 623 } 624 isEmpty()625 public boolean isEmpty() { 626 return true; 627 } 628 onGroupExpanded(int groupPosition)629 public void onGroupExpanded(int groupPosition) { 630 } 631 onGroupCollapsed(int groupPosition)632 public void onGroupCollapsed(int groupPosition) { 633 } 634 getCombinedChildId(long groupId, long childId)635 public long getCombinedChildId(long groupId, long childId) { 636 return 0; 637 } 638 getCombinedGroupId(long groupId)639 public long getCombinedGroupId(long groupId) { 640 return 0; 641 } 642 } 643 644 private class MockExpandableListView extends ExpandableListView { MockExpandableListView(Context context)645 public MockExpandableListView(Context context) { 646 super(context); 647 } 648 MockExpandableListView(Context context, AttributeSet attrs)649 public MockExpandableListView(Context context, AttributeSet attrs) { 650 super(context, attrs); 651 } 652 MockExpandableListView(Context context, AttributeSet attrs, int defStyle)653 public MockExpandableListView(Context context, AttributeSet attrs, int defStyle) { 654 super(context, attrs, defStyle); 655 } 656 657 @Override dispatchDraw(Canvas canvas)658 protected void dispatchDraw(Canvas canvas) { 659 super.dispatchDraw(canvas); 660 } 661 } 662 } 663