2013-04-22 33 views
1

您的内容必须有一个ListView,其id属性是 'android.R.id.list'内容必须有一个ListView其id属性为 '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" /> 

+0

extend'ListFragment'? – midhunhk 2013-04-22 09:44:41

回答

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

你给内部ListFragmentonCreateView方法错布局。

+0

好赶家伙。 ;-) – 2013-04-22 09:45:53

+0

欢迎兄弟.... – Triode 2013-04-22 09:46:27

+0

谢谢,你说得对。我甚至没有注意到那部分代码。 – user2236580 2013-04-22 09:51:23

相关问题