content必须有一个ListView,其id属性为'android.R.id.list'

时间:2013-04-22 09:42:39

标签: android android-layout android-listview

  

您的内容必须包含其属性为的ListView   'android.R.id.list'

我收到的错误是我之前处理过的。我尝试了一堆不同的ID等等,但它没有帮助。正如您在下面看到的那样,名称似乎是正确的。我认为它与我刚接触片段和listfragments等事实有关。我已经发布了相关的代码,如果需要更多代码,我会提供它。

有什么想法吗?

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" />

1 个答案:

答案 0 :(得分:3)

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

您在ListFragment的{​​{1}}方法中提供了错误的布局。