我有一個包含列表視圖的片段。在這一片段,我試圖儘快導航到另一個片段在列表中的項目之一被點擊,但我得到一個錯誤,指出無法從具有列表視圖的片段導航到另一個片段
java.lang.UnsupportedOperationException:addView(查看)中不支持適配器視圖
這是我的代碼
private void setupList(View view) {
//super.onCreate(savedInstanceState);
//setContentView(R.layout.icons_main);
CustomListAdapter adapter = new CustomListAdapter(this.getActivity(), itemname, imgid);
//CustomListAdapter adapter=new CustomListAdapter(this, itemname, imgid);
list = (ListView) view.findViewById(R.id.list);
//(ListView)view.findViewById(R.id.lv_listview);
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
String Slecteditem = itemname[+position];
// Toast.makeText(getApplicationContext(), Slecteditem, Toast.LENGTH_SHORT).show();
Fragment fragment = new SensorInformationChildFragment();
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.list, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
}
錯誤我得到
java.lang.UnsupportedOperationException: addView(View) is not supported in AdapterView
at android.widget.AdapterView.addView(AdapterView.java:452)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1124)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1290)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:801)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1677)
at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:536)
at android.os.Handler.handleCallback(Handler.java:808)
at android.os.Handler.dispatchMessage(Handler.java:103)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:5299)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:829)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:645)
at dalvik.system.NativeStart.main(Native Method)
AdapterView(ListView)不喜歡當你搞砸了它的孩子......而你用wana替換em .. 。只是使用一些外部容器...編輯:恕我直言,它會更好地將ListView替換爲ListFragment ...然後,ListView將成爲你取代的ListFragment的一部分,所以你不會有這樣的問題... – Selvin