您的内容必须有一个ListView的id属性是 android.R.id.list
我得到这个错误,我已经处理过。我已经尝试了很多不同的ID等,但它没有帮助。正如你可以看到下面的名字做似乎是正确的。我认为这是与我是新来的碎片和listfragments等事实。我已经发布code中的相关内容,如果有更多的要求,我会提供它。
任何想法?
公共类DisplayInfo扩展FragmentActivity {SectionsPagerAdapter mSectionsPagerAdapter;/ ** *本{@link ViewPager}将承载部分内容。 * /ViewPager mViewPager;@覆盖保护无效的onCreate(捆绑savedInstanceState){ super.onCreate(savedInstanceState); 的setContentView(R.layout.activity_display_info); mSectionsPagerAdapter =新SectionsPagerAdapter( getSupportFragmentManager()); 新CreateTimetablesTask()执行(); Log.d(完成任务,任务); //设置的ViewPager与部分适配器。 mViewPager =(ViewPager)findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter);}
}
公共类DummySectionFragment扩展ListFragment {私人整数arrayListId;ViewGroup中myViewGroup;公共静态最后弦乐CATEGORY_POSITION =SECTION_NUMBER;公共静态的newInstance DummySectionFragment(INT POS){ DummySectionFragment F =新DummySectionFragment(); //供应NUM输入作为参数。 捆绑ARGS =新包(); args.putInt(CATEGORY_POSITION,POS) f.setArguments(参数); 返回F;}@覆盖公共无效的onCreate(捆绑savedInstanceState){ //获取ID为您的数组列表 super.onCreate(savedInstanceState); arrayListId = getArguments()!= NULL? getArguments()调用getInt(CATEGORY_POSITION) - 1:1;}//创建列表视图布局@覆盖公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){ myViewGroup =容器; 视图V = inflater.inflate(R.layout.list_row,集装箱,FALSE); 返回伏;}@覆盖公共无效onActivityCreated(捆绑savedInstanceState){ super.onActivityCreated(savedInstanceState); ArrayAdapter< SingleClass> arrayAdapter = 新ArrayAdapter&所述; SingleClass>(getActivity(),R.layout.fragment_display_info,android.R.id.list); setListAdapter(arrayAdapter);}}
fragment_display_info.xml
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android 机器人:方向=垂直 机器人:layout_width =match_parent 机器人:layout_height =match_parent>< ListView控件 机器人:ID =@机器人:ID /列表 机器人:layout_width =FILL_PARENT 机器人:layout_height =WRAP_CONTENT>< /&的ListView GT;< / LinearLayout中>
activity_display_info.xml
< android.support.v4.view.ViewPager的xmlns:机器人=http://schemas.android.com/apk/res/android的xmlns:工具=http://schemas.android.com/tools机器人:ID =@ + ID /寻呼机机器人:layout_width =match_parent机器人:layout_height =match_parent工具:DisplayOnlineTimetable上下文=><! - 这个标题条会显示当前可见的页面标题,以及网页标题相邻的页面。 - >< android.support.v4.view.PagerTitleStrip 机器人:ID =@ + ID / pager_title_strip 机器人:layout_width =match_parent 机器人:layout_height =WRAP_CONTENT 机器人:layout_gravity =顶 机器人:背景=#33b5e5 机器人:paddingBottom会=4DP 机器人:paddingTop =4DP 机器人:文字颜色=#FFF/>
解决方案
@覆盖公共查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState){ myViewGroup =容器; 视图V = inflater.inflate(R.layout.fragment_display_info,集装箱,FALSE); 返回伏;}
您在 ListFragment
的 onCreateView
方法。
Your content must have a ListView whose id attribute is 'android.R.id.list'
I'm getting this error which I have dealt with before. I have tried a bunch of different ids and so on but it's not helping. As you can see below the names do appear to be correct. I think it has something to do with the fact I am new to fragments and listfragments and so on. I have posted the relevant bits of code, if more is required I will provide it.
Any ideas?
public class DisplayInfo extends FragmentActivity {
SectionsPagerAdapter mSectionsPagerAdapter;
/**
* The {@link ViewPager} that will host the section contents.
*/
ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_display_info);
mSectionsPagerAdapter = new SectionsPagerAdapter(
getSupportFragmentManager());
new CreateTimetablesTask().execute();
Log.d("task done", "task");
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mSectionsPagerAdapter);
}
}
public class DummySectionFragment extends ListFragment {
private Integer arrayListId;
ViewGroup myViewGroup;
public static final String CATEGORY_POSITION = "section_number";
public static DummySectionFragment newInstance(int pos) {
DummySectionFragment f = new DummySectionFragment();
// Supply num input as an argument.
Bundle args = new Bundle();
args.putInt(CATEGORY_POSITION, pos);
f.setArguments(args);
return f;
}
@Override
public void onCreate(Bundle savedInstanceState) {
//get the id for your array list
super.onCreate(savedInstanceState);
arrayListId = getArguments() != null ? getArguments().getInt(CATEGORY_POSITION) - 1 : 1;
}
//create the list view layout
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myViewGroup = container;
View v = inflater.inflate(R.layout.list_row, container, false);
return v;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
ArrayAdapter<SingleClass> arrayAdapter =
new ArrayAdapter<SingleClass>(getActivity(), R.layout.fragment_display_info, android.R.id.list);
setListAdapter(arrayAdapter);
}
}
fragment_display_info.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
activity_display_info.xml
<android.support.v4.view.ViewPager xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DisplayOnlineTimetable" >
<!--
This title strip will display the currently visible page title, as well as the page
titles for adjacent pages.
-->
<android.support.v4.view.PagerTitleStrip
android:id="@+id/pager_title_strip"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:background="#33b5e5"
android:paddingBottom="4dp"
android:paddingTop="4dp"
android:textColor="#fff" />
解决方案 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
myViewGroup = container;
View v = inflater.inflate(R.layout.fragment_display_info, container, false);
return v;
}
You are giving wrong layout inside ListFragment
's onCreateView
method.