0
用gridview創建片段的正確方法是什麼? 我可以這樣做嗎? GridView的Viewpager片段
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"
android:numColumns="2"
android:verticalSpacing="10dp"
android:horizontalSpacing="0dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>
?如何添加適配器在運行時的GridView控件項目添加到它?
private void initialisePaging() {
List<Fragment> fragments = new Vector<Fragment>();
fragments.add(Fragment.instantiate(this, fragment1.class.getName()));
fragments.add(Fragment.instantiate(this, fragment2.class.getName()));
fragments.add(Fragment.instantiate(this, fragment3.class.getName()));
this.mPagerAdapter = new MyPagerAdapter(super.getSupportFragmentManager(), fragments);
//this.mPagerAdapter.setListener(this);
Log.e("init", "message");
pager = (ViewPager)super.findViewById(R.id.viewpager_menu);
pager.setAdapter(this.mPagerAdapter);
GridView gridView = (GridView)findViewById(R.layout.menu1_fragment);
}
當我這樣做時,gridview爲空,我無法將適配器附加到它。
我該如何得到gridView? @Override \t public Object instantiateItem(ViewGroup container,int position){ \t \t Fragment g = fragments.get(position); \t \t GridView gridView =(GridView)g.getView(); \t \t \t return super.instantiateItem(container,position); \t} GridView仍然爲空。 – Romans