Result.java:
Fragment f = new GridViewFragement();
FragmentManager fm = getFragmentManager();
fm.beginTransaction().replace(R.id.grid, f).commit();
Activity_result.xml :
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/grid"
android:orientation="vertical"
>
</LinearLayout>
Row_grid.xml: defines a grid item
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<ImageView
android:id="@+id/item_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:src="@drawable/home" >
</ImageView>
<TextView
android:id="@+id/item_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:textSize="15sp" >
</TextView>
</LinearLayout>
grid.xml:
<GridView
android:id="@+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_margin="4dp"
android:columnWidth="80dp"
android:gravity="center"
android:numColumns="auto_fit"
android:stretchMode="columnWidth"
android:fadeScrollbars="false"
/>
On create in grid view fragment:
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
// on create for activity
View view = inflater.inflate(R.layout.grid, container, false);
Bitmap homeIcon = BitmapFactory.decodeResource
(this.getResources(), R.drawable.home);
Bitmap userIcon = BitmapFactory.decodeResource
(this.getResources(), R.drawable.personal);
//
gridArray.add(new Item(homeIcon,"Home"));
gridArray.add(new Item(userIcon,"Personal"));
gridArray.add(new Item(homeIcon,"Home"));
gridArray.add(new Item(userIcon,"User"));
gridArray.add(new Item(homeIcon,"Building"));
gridArray.add(new Item(userIcon,"User"));
gridArray.add(new Item(homeIcon,"Home"));
gridArray.add(new Item(userIcon,"xyz"));
gridArray.add(new Item(homeIcon,"Home"));
gridArray.add(new Item(userIcon,"User"));
gridArray.add(new Item(homeIcon,"House"));
gridArray.add(new Item(userIcon,"Friend"));
gridView = (GridView) view.findViewById(R.id.gridView1);
customGridAdapter =newCustomGridViewAdapter
(view.getContext(),R.layout.row_grid,gridArray);
gridView.setAdapter(customGridAdapter);
return view;
}
Having issues trying to show all data of my gridview. it cuts halfway only the first three items are showing in a row. sorry, I'm unable to post pictures because I'm only rep 1. I have tried putting scrollviews and making the scroll bar appear but it just won't scroll or show all of its data