我是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 –