我从谷歌名称“viewpager符合swipey标签”实现了这个swipey标签代码。现在对于片段活动,每个都使用xml布局设置。我希望此活动显示网格视图。我尝试实现http://developer.android.com上解释的网格视图示例,但它为gridview.setAdapter上的findgridviewbyid和imageadapter构造函数提供了一些错误。 如何实现网格视图仅显示此片段中的图像。
public class StockTabFragment extends Fragment {
public static Fragment newInstance(String title) {
StockTabFragment f = new StockTabFragment();
Bundle args = new Bundle();
args.putString("title", title);
f.setArguments(args);
return f;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup root = (ViewGroup) inflater.inflate(R.layout.stock_tab_fragment, null);
return root;
}
private ViewGroup createGridView(ViewGroup root) {
GridView gridview = (GridView) findViewById(R.id.gridview);
gridview.setAdapter(new ImageAdapter(this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
Toast.makeText(StockTabFragment.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
return root;
}
}
Stock_Tab_Fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>