您的内容必须具有ID属性为的ListView
  'android.R.id.list'


我遇到这个错误,之前已经处理过。我尝试了很多不同的ID,等等,但没有帮助。正如您在下面看到的,名称确实是正确的。我认为这与我不熟悉片段和片段片段等有关。我已经发布了相关的代码,如果需要更多的代码,我会提供。

有任何想法吗?

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;
}


您在ListFragmentonCreateView方法中给出了错误的布局。

09-27 00:22