By pressing your Activity button, you could call a new Activity, containing the desired gridview.
Example:
btnOpen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(this, NovaActivity.class);
startActivity(intent);
}
});
In your "Novaactivity", you will initialize the same way you start the first one, but your Activity’s xml will contain the Gridiview component.
Example:
<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridView1"
android:numColumns="auto_fit"
android:gravity="center"
android:columnWidth="50dp"
android:stretchMode="columnWidth"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
</GridView>
This example xml only serves to tell android that you will have a grid on your screen. To format the contents of this grid, you will need an Adapter and the xml of this Adapter. The content of the "getView()" function of Adapter is exactly for displaying each cell of your gridview.
Example:
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View gridView;
if (convertView == null) {
gridView = new View(context);
// get layout from mobile.xml
gridView = inflater.inflate(R.layout.mobile, null);
// set value into textview
TextView textView = (TextView) gridView
.findViewById(R.id.grid_item_label);
textView.setText(mobileValues[position]);
In this excerpt I say that the component "grid_item_label" will have as content the position "position" of the vector "mobileValues". That is, for each space on your grid, the getView() function will be executed. Now, the content of each cell will be determined by you. The vector "mobileValues" can have any attribute, just present it in your Adapter, that it will appear on the screen.
In the case of xml of the contents of your grid, just insert the elements that each cell will have. In the case of the example, xml would have only one text.
Example:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp" >
<TextView
android:id="@+id/grid_item_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@+id/label"
android:layout_marginTop="5px"
android:textSize="15px" >
</TextView>
</LinearLayout>
You may not know the data in the file, but you need to know the type of data you will receive. This data will be stored in your vector, so that each position is displayed on your Adapter. (:
Pedro, to half covered in this project ://type, as I will be reading the xml file by "pressing" the button that will be in the application, I do not know how to put in Adapter the values and much less in Activity since I supposedly do not know each data of the file. I’m already using Imageadapter, the custom table and some tips on the same links. Have any idea how to get started with Activity?
– Mayla Campos