我是Android新手。我为联系人示例创建了一个自动生成的列表活动。ListFragment的可扩展列表适配器
我有两件事情 -
ContactListActivity.java
/** auto generated code /**
在ContactListFragment.java
我已经修改了这个方法来设置我的列表。
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/*** some code **/
setListAdapter(new ArrayAdapter<MyContact.Contact>(
getActivity(),
android.R.layout.simple_list_item_activated_1,
android.R.id.text1,
contactList));
我还没有修改任何xml。
现在我想显示一个可扩展列表,而不是简单列表。我写了一个简单的SimpleExpandableListAdapter
SimpleExpandableListAdapter myAdapter = new SimpleExpandableListAdapter(
getActivity(),
groupData,
android.R.layout.simple_expandable_list_item_1,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 },
childData,
android.R.layout.simple_expandable_list_item_2,
new String[] { NAME, IS_EVEN },
new int[] { android.R.id.text1, android.R.id.text2 }
);
但我不能调用
setListAdapter(myAdapter)
它显示编译错误成功设置该适配器。
android.widget.ListAdapter can not be applied to android.widget.SimpleExpandableListAdapter
什么样的变化我必须弥补这方面进行合作?
这是我的activity_contact_list.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/contact_list"
android:name="com.example.sarvesh.litecontacts.ContactListFragment"
android:layout_width="match_parent" android:layout_height="match_parent"
android:layout_marginLeft="16dp" android:layout_marginRight="16dp"
tools:context=".ContactListActivity" tools:layout="@android:layout/expandable_list_content" />
'它显示编译错误.'哪个错误? –
android.widget.ListAdapter无法应用于android.widget.SimpleExpandableListAdapter –