NoSuchMethod exception for setShowDividers

2019-07-18 01:47发布

问题:

I would like to display a sort of ListView with divider lines between each item. Because each row of this list will show a different custom view I thought it would be easier to have a TableLayout instead and use setShowDividers and SHOW_DIVIDER_MIDDLE in order to show that white line between each item.

Why do I get NoSuchMethod exception at setShowDividers?

 TableLayout table = (TableLayout)findViewById(R.id.my_table_layout);
 if( table != null )
 {
      table.setShowDividers(TableLayout.SHOW_DIVIDER_MIDDLE);
 }

I also get the same error if I cast everything to LinearLayout instead.

回答1:

What API target are you using? setShowDividers was added in API level 11 (Honeycomb).